package com.classes;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import com.mbbmap.app.manager.ConfigManager;
import com.mbbmap.app.manager.DBConnectionManager;
import com.mbbmap.util.Constants;

public class AutoScript {
	protected static String date_format = "ddMMyyyy";
	protected static String application_id = "";
	protected static String user_id = "";
	protected static long ms = 1000;
	
	protected static String[] init_arr(int len){
		String[] s_arr = new String[len];
		
		for(int i=0; i<s_arr.length; i++){
			s_arr[i] = "";
		}
		
		return s_arr;
	}
	
	protected static String today_date(String format){
		SimpleDateFormat df = new SimpleDateFormat(format);
		
		return df.format(new Date());
	}
	
	protected static String today_date(String format, Date d){
		SimpleDateFormat df = new SimpleDateFormat(format);
		
		return df.format(d);
	}
	
	protected static String format_decimal(String in, int len){
		Double d;
		String ds = in;
		
		try {
			d = Double.parseDouble(in);
			d = d * 1000;
			
			ds = String.format("%.0f", d);
			ds = String.format("%0" + len + "d", Integer.parseInt(ds));
			
		} catch (Exception e){
			
		}
		
		return ds;
	}
	
	protected static String format_int(String in, int len){
		String ds = in;
		
		try{
			ds = String.format("%0" + len + "d", Integer.parseInt(in));
		} catch (Exception e){
			
		}
		
		return ds;
	}
	
	public static void clear() throws Exception {

        String connectionPool = ConfigManager.getInstance().getConnectionPool();
        DBConnectionManager connMgr = DBConnectionManager.getInstance();
        Connection conn = connMgr.getConnection(connectionPool, 10000);
		
        PreparedStatement statement = null;
        try {

			String sql = "delete from tbl_autoscript "
					+ "where application_id = ? ";
			
			statement = conn.prepareStatement(sql);
			
			statement.setString(1, AutoScript.application_id.length() > 0 ? AutoScript.application_id : null);
			statement.execute();
		
        } finally {
        	if (statement != null) {
        		try { statement.close(); } catch (Exception e) {}
        	}
			connMgr.freeConnection(connectionPool, conn);
		}
	}
	
	public static void clear(int case_id, String u_id, String u_group) throws Exception {
		Casemast c = CasemastFactory.getCaseMast(u_group, case_id);
		
		AutoScript.application_id = c.getReferenceNo();
		AutoScript.user_id = u_id;
		
		AutoScript.clear();
	}
	
	public static void save(String screen_id, TreeMap<String, String[]> arr) throws Exception{
		for(Map.Entry<String, String[]> entry : arr.entrySet()) {
			String product_id = entry.getKey();
			String screen_id2 = screen_id;
			
			if(product_id.indexOf(":") >= 0){
				String[] prod_arr = product_id.split(":");
				
				product_id = prod_arr[0];
				screen_id2 = screen_id + "_" + prod_arr[1];
			}
			AutoScript.save(screen_id2, product_id, entry.getValue());
		}
	}
	
	public static void save(String screen_id, String product_id, String[] s_arr) throws Exception{

        String connectionPool = ConfigManager.getInstance().getConnectionPool();
        DBConnectionManager connMgr = DBConnectionManager.getInstance();
        Connection conn = connMgr.getConnection(connectionPool, 10000);
        
        try {
			String sql = "insert into tbl_autoscript(application_id, product_id, screen_id, content_text, "
					+ "created_by, created_date, updated_by, updated_date) "
					+ "values(?, ?, ?, ?, "
					+ "?, sysdate, ?, sysdate)";
			
			PreparedStatement statement = conn.prepareStatement(sql);
			
			StringBuffer content_text = new StringBuffer();
			String sep = "";
			for(String s : s_arr){
				content_text
					.append(sep)
					.append(s);
				
				sep = ",";
			}
			
			statement.setString(1, AutoScript.application_id.length() > 0 ? AutoScript.application_id : null);
			statement.setString(2, product_id);
			statement.setString(3, screen_id);
			statement.setString(4, content_text.toString());
			statement.setString(5, AutoScript.user_id.length() > 0 ? AutoScript.user_id : null);
			statement.setString(6, AutoScript.user_id.length() > 0 ? AutoScript.user_id : null);
			
			statement.execute();
			
			statement.close();
		} finally {
			connMgr.freeConnection(connectionPool, conn);
		}
	}
	
	public static void generate(int case_id, int outlet_id, String u_id, String u_group) throws Exception{
		Casemast c = CasemastFactory.getCaseMast(u_group, case_id);
		c.loadOutlets();
		
		AutoScript.application_id = c.getReferenceNo();
		AutoScript.user_id = u_id;
		
		AutoScript.clear();
		
		for(CaseOutlet c_outlet : c.getOutlets()){
			if(c_outlet.getOutlet().getId() == Long.parseLong(Integer.toString(outlet_id))){
				if(c.getCountryCode().equals("MY")){
					AutoScript.AMAG01(c, c_outlet);
				}
				
				AutoScript.PCMA01(c, c_outlet);
				AutoScript.PCMA02(c, c_outlet);
				AutoScript.PCMA03(c, c_outlet);
				AutoScript.PCMA04(c, c_outlet);
				AutoScript.PCMA05(c, c_outlet);
				
				if(c.getCountryCode().equals("MY")){
					AutoScript.AMAM01(c, c_outlet);
					AutoScript.AMAM02(c, c_outlet);
					AutoScript.AMAA01("SA", c, c_outlet);
					AutoScript.AMAA01("CO", c, c_outlet);
					AutoScript.AMAA01("PA", c, c_outlet);
					AutoScript.AMAB01(c, c_outlet);
					AutoScript.AMAB02(c, c_outlet);
					AutoScript.AMDM01(c, c_outlet);
					AutoScript.AMDM02(c, c_outlet);
				}
				
				break;
			}
		}
	}
	
	public static String[] concat(String[] a, String[] b){
		int aLen = a.length;
		int bLen = b.length;
		
		String[] c = new String[aLen+bLen];
		
		System.arraycopy(a, 0, c, 0, aLen);
		System.arraycopy(b, 0, c, aLen, bLen);
		
		return c;
	}
	
	public static String[] DATA(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(620);
		
		s_arr[0] = c.getType();
		s_arr[1] = c.getMerchant().getOwnershipStatus();
		s_arr[2] = c.getMerchant().getRegisteredName();
		s_arr[3] = c.getMerchant().getRegisteredNo();
		s_arr[4] = c.getMerchant().getDesc();
		s_arr[5] = c.getMerchant().getMCCCode();
		s_arr[6] = c.getMerchant().getPaidUpCapital();
		s_arr[7] = c.getMerchant().getRecallBarcode();
		s_arr[8] = c.getMerchant().getYearInBusiness();
		s_arr[9] = c.getMerchant().getAvgTicketSize();
		s_arr[10] = c.getAcquirer();
		s_arr[11] = c.getMerchant().getCurrBank();
		s_arr[12] = c.getMerchant().getCurrAccNo();
		s_arr[13] = c.getMerchant().getCurrAvgDeposit();
		
		String curr_avg_deposit_dtl = c.getMerchant().getCurrAvgDepositDtl();
		JSONArray avg_deposit_arr = (JSONArray) JSONValue.parse(curr_avg_deposit_dtl);
		
		if(avg_deposit_arr == null){
			s_arr[14] = "";
			s_arr[15] = "";
			s_arr[16] = "";
			s_arr[17] = "";
			s_arr[18] = "";
			s_arr[19] = "";
			s_arr[20] = "";
			s_arr[21] = "";
			s_arr[22] = "";
		}
		else {
			int last_index = 13;
			
			for(int k = 0; k < avg_deposit_arr.size(); k++) {
				String string = avg_deposit_arr.get(k).toString();
				JSONObject obj = (JSONObject)JSONValue.parse(string);
				
				String month = (obj.get("month") == null) ? "" : obj.get("month").toString().trim();
				String total_deposit = (obj.get("total_deposit") == null) ? "" : obj.get("total_deposit").toString().trim();
				String balance = (obj.get("balance") == null) ? "" : obj.get("balance").toString().trim();
				
				++last_index;
				s_arr[last_index] = month;
				
				++last_index;
				s_arr[last_index] = total_deposit;
				
				++last_index;
				s_arr[last_index] = balance;
			}
			
			for(int k = last_index + 1; k <= 22; k++) {
				s_arr[k] = "";
			}
		}
		
		
		String amex_auth_sign = c.getMerchant().getAmexAuthSign();
		JSONArray amex_auth_sign_arr = (JSONArray) JSONValue.parse(amex_auth_sign);
		
		if(amex_auth_sign_arr == null){
			s_arr[23] = "";
			s_arr[24] = "";
			s_arr[25] = "";
			s_arr[26] = "";
			s_arr[27] = "";
			s_arr[28] = "";
			s_arr[29] = "";
			s_arr[30] = "";
			s_arr[31] = "";
			s_arr[32] = "";
			s_arr[33] = "";
			s_arr[34] = "";
		}
		else {
			int last_index = 22;
			
			for(int k = 0; k < amex_auth_sign_arr.size(); k++) {
				String string = amex_auth_sign_arr.get(k).toString();
				JSONObject obj = (JSONObject)JSONValue.parse(string);
				
				String title = (obj.get("title") == null) ? "" : obj.get("title").toString().trim();
				String name = (obj.get("name") == null) ? "" : obj.get("name").toString().trim();
				String designation = (obj.get("designation") == null) ? "" : obj.get("designation").toString().trim();
				String ic_no = (obj.get("ic_no") == null) ? "" : obj.get("ic_no").toString().trim();
				String date_of_birth = (obj.get("date_of_birth") == null) ? "" : obj.get("date_of_birth").toString().trim();
				String gender = (obj.get("gender") == null) ? "" : obj.get("gender").toString().trim();
				
				++last_index;
				s_arr[last_index] = title;
				
				++last_index;
				s_arr[last_index] = name;
				
				++last_index;
				s_arr[last_index] = designation;
				
				++last_index;
				s_arr[last_index] = ic_no;
				
				++last_index;
				s_arr[last_index] = date_of_birth;
				
				++last_index;
				s_arr[last_index] = gender;
			}
			
			
			for(int k = last_index + 1; k <= 34; k++) {
				s_arr[k] = "";
			}
		}
		
		
		s_arr[35] = c_outlet.getOutlet().getName();
		s_arr[36] = c_outlet.getOutlet().getMerchant().getRegisteredName();
		s_arr[37] = c_outlet.getOutlet().getMerchant().getRegisteredNo();
		s_arr[38] = c_outlet.getOutlet().getLisenceNo();
		s_arr[39] = c_outlet.getOutlet().getLicenseType();
		s_arr[40] = c_outlet.getOutlet().getLicenseState();
		s_arr[41] = c_outlet.getOutlet().getLicenseIssuer();
		s_arr[42] = c_outlet.getOutlet().getLicenseExpiry();
		s_arr[43] = c_outlet.getOutlet().getCTName();
		s_arr[44] = c_outlet.getOutlet().getCTDesignation();
		s_arr[45] = c_outlet.getOutlet().getCTEmail();
		s_arr[46] = c_outlet.getOutlet().getCTTel();
		s_arr[47] = c_outlet.getOutlet().getCTFax();
		s_arr[48] = c_outlet.getOutlet().getRiskLevel();
		s_arr[49] = c_outlet.getESARefNo();
		s_arr[50] = c_outlet.getNumTerminal();
		s_arr[51] = c_outlet.getTrmRental();
		s_arr[52] = c_outlet.getTrmOwner();
		s_arr[53] = c_outlet.getTrmDepositWired();
		s_arr[54] = c_outlet.getTrmDepositWireless();
		s_arr[55] = c_outlet.getTrmRentalDepositWired();
		s_arr[56] = c_outlet.getTrmRentalDepositWireless();
		s_arr[57] = c_outlet.getTrmRentalAdvance();
		s_arr[58] = c_outlet.getChequeAmt();
		
		String bank_issuer_branch = c_outlet.getChequeIssuer();
		
		if(bank_issuer_branch.length() > 0){
			String bank_issuer = bank_issuer_branch.substring(0, bank_issuer_branch.lastIndexOf('|'));
			String bank_branch = bank_issuer_branch.substring(bank_issuer_branch.lastIndexOf('|') + 1);
			
			s_arr[59] = bank_issuer;
			s_arr[60] = bank_branch;
		}
		else {
			s_arr[59] = "";
			s_arr[60] = "";
		}
		
		
		s_arr[61] = c_outlet.getChequeNo();
		s_arr[62] = c_outlet.getChequeDate();
		s_arr[63] = c_outlet.getTerminalID();
		s_arr[64] = c_outlet.getTerminalIDNo();
		s_arr[65] = c_outlet.getTerminalInstallDate();
		
		
		if(c_outlet.getOutlet().getPaymentOpt().length() > 0){
			JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getPaymentOpt());
			
			s_arr[66] = (obj.get("cust_1") == null) ? "" : obj.get("cust_1").toString();
			s_arr[67] = (obj.get("cust_2") == null) ? "" : obj.get("cust_2").toString();
			s_arr[68] = (obj.get("cust_3") == null) ? "" : obj.get("cust_3").toString();
			s_arr[69] = (obj.get("visa_1") == null) ? "" : obj.get("visa_1").toString();
			s_arr[70] = (obj.get("visa_2") == null) ? "" : obj.get("visa_2").toString();
			s_arr[71] = (obj.get("visa_3") == null) ? "" : obj.get("visa_3").toString();
			s_arr[72] = (obj.get("visa_4") == null) ? "" : obj.get("visa_4").toString();
			s_arr[73] = (obj.get("visa_5") == null) ? "" : obj.get("visa_5").toString();
			s_arr[74] = (obj.get("visa_6") == null) ? "" : obj.get("visa_6").toString();
			s_arr[75] = (obj.get("visa_7") == null) ? "" : obj.get("visa_7").toString();
			s_arr[76] = (obj.get("amex_1") == null) ? "" : obj.get("amex_1").toString();
			s_arr[77] = (obj.get("amex_2") == null) ? "" : obj.get("amex_2").toString();
			s_arr[78] = (obj.get("amex_3") == null) ? "" : obj.get("amex_3").toString();
			s_arr[79] = (obj.get("amex_4") == null) ? "" : obj.get("amex_4").toString();
			s_arr[80] = (obj.get("amex_5") == null) ? "" : obj.get("amex_5").toString();
			s_arr[81] = (obj.get("amex_6") == null) ? "" : obj.get("amex_6").toString();
			s_arr[82] = (obj.get("amex_7") == null) ? "" : obj.get("amex_7").toString();
			s_arr[83] = (obj.get("amex_8") == null) ? "" : obj.get("amex_8").toString();
			s_arr[84] = (obj.get("amex_9") == null) ? "" : obj.get("amex_9").toString();
			s_arr[85] = (obj.get("amex_10") == null) ? "" : obj.get("amex_10").toString();
			s_arr[86] = (obj.get("union_pay_1") == null) ? "" : obj.get("union_pay_1").toString();
			s_arr[87] = (obj.get("ezypay_1") == null) ? "" : obj.get("ezypay_1").toString();
			s_arr[88] = (obj.get("ezypay_2") == null) ? "" : obj.get("ezypay_2").toString();
			s_arr[89] = (obj.get("mbb_phi_1") == null) ? "" : obj.get("mbb_phi_1").toString();
			s_arr[90] = (obj.get("mbb_phi_2") == null) ? "" : obj.get("mbb_phi_2").toString();
			s_arr[91] = (obj.get("mbb_sg_1") == null) ? "" : obj.get("mbb_sg_1").toString();
			s_arr[92] = (obj.get("mbb_sg_2") == null) ? "" : obj.get("mbb_sg_2").toString();
		}
		else {
			for(int k = 66; k <= 92; k++) {
				s_arr[k] = "";
			}
		}
		
		
		if(c_outlet.getOutlet().getStatementOpt().length() > 0){
			JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getStatementOpt());
			
			s_arr[93] = (obj.get("visa_1") == null) ? "" : obj.get("visa_1").toString();
			s_arr[94] = (obj.get("visa_2") == null) ? "" : obj.get("visa_2").toString();
			s_arr[95] = (obj.get("visa_3") == null) ? "" : obj.get("visa_3").toString();
			s_arr[96] = obj.get("amex_1") == null ? "" : obj.get("amex_1").toString();
			s_arr[97] = obj.get("amex_2") == null ? "" : obj.get("amex_2").toString();
		}
		else {
			for(int k = 93; k <= 97; k++) {
				s_arr[k] = "";
			}
		}
		
		
		if(c_outlet.getOutlet().getOtherInfo().length() > 0){
			JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getOtherInfo());
			
			s_arr[98] = (obj.get("officer_code") == null) ? "" : obj.get("officer_code").toString();
			s_arr[99] = (obj.get("user_code_1") == null) ? "" : obj.get("user_code_1").toString();
			s_arr[99] = s_arr[99].trim();
			s_arr[100] = (obj.get("user_code_2") == null) ? "" : obj.get("user_code_2").toString();
			s_arr[100] = s_arr[100].trim();
			s_arr[101] = (obj.get("user_code_3") == null) ? "" : obj.get("user_code_3").toString();
			s_arr[101] = s_arr[101].trim();
			s_arr[102] = (obj.get("chain_merchant") == null) ? "" : obj.get("chain_merchant").toString();
			s_arr[103] = (obj.get("hierarchy_no") == null) ? "" : obj.get("hierarchy_no").toString();
			s_arr[104] = (obj.get("level") == null) ? "" : obj.get("level").toString();
			s_arr[105] = (obj.get("servicing_rep") == null) ? "" : obj.get("servicing_rep").toString();
			s_arr[106] = (obj.get("sales_rep") == null) ? "" : obj.get("sales_rep").toString();
			s_arr[107] = (obj.get("level_5") == null) ? "" : obj.get("level_5").toString();
			s_arr[108] = (obj.get("level_6") == null) ? "" : obj.get("level_6").toString();
		}
		else {
			for(int k = 98; k <= 108; k++) {
				s_arr[k] = "";
			}
		}
		
		
		if(c_outlet.getOutlet().getAddress().length() > 0){
			JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress());
			
			s_arr[109] = (obj.get("line_1") == null) ? "" : obj.get("line_1").toString().trim();
			s_arr[110] = (obj.get("line_2") == null) ? "" : obj.get("line_2").toString().trim();
			s_arr[111] = (obj.get("line_3") == null) ? "" : obj.get("line_3").toString().trim();
			s_arr[112] = (obj.get("line_4") == null) ? "" : obj.get("line_4").toString().trim();
			s_arr[113] = (obj.get("postal_code") == null) ? "" : obj.get("postal_code").toString().trim();
			s_arr[114] = (obj.get("city") == null) ? "" : obj.get("city").toString().trim();
			s_arr[115] = (obj.get("region_code") == null) ? "" : obj.get("region_code").toString().trim();
		}
		else {
			for(int k = 109; k <= 115; k++) {
				s_arr[k] = "";
			}
		}
		
		
		if(c_outlet.getOutlet().getAddress2().length() > 0){
			JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress2());
			
			s_arr[116] = (obj.get("line_1") == null) ? "" : obj.get("line_1").toString().trim();
			s_arr[117] = (obj.get("line_2") == null) ? "" : obj.get("line_2").toString().trim();
			s_arr[118] = (obj.get("line_3") == null) ? "" : obj.get("line_3").toString().trim();
			s_arr[119] = (obj.get("line_4") == null) ? "" : obj.get("line_4").toString().trim();
			s_arr[120] = (obj.get("postal_code") == null) ? "" : obj.get("postal_code").toString().trim();
			s_arr[121] = (obj.get("city") == null) ? "" : obj.get("city").toString().trim();
			s_arr[122] = (obj.get("region_code") == null) ? "" : obj.get("region_code").toString().trim();
		}
		else {
			for(int k = 116; k <= 122; k++) {
				s_arr[k] = "";
			}
		}
		
		
		if(c_outlet.getOutlet().getAddress3().length() > 0){
			JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress3());
			
			s_arr[123] = (obj.get("line_1") == null) ? "" : obj.get("line_1").toString().trim();
			s_arr[124] = (obj.get("line_2") == null) ? "" : obj.get("line_2").toString().trim();
			s_arr[125] = (obj.get("line_3") == null) ? "" : obj.get("line_3").toString().trim();
			s_arr[126] = (obj.get("line_4") == null) ? "" : obj.get("line_4").toString().trim();
			s_arr[127] = (obj.get("postal_code") == null) ? "" : obj.get("postal_code").toString().trim();
			s_arr[128] = (obj.get("city") == null) ? "" : obj.get("city").toString().trim();
			s_arr[129] = (obj.get("region_code") == null) ? "" : obj.get("region_code").toString().trim();
		}
		else {
			for(int k = 123; k <= 129; k++) {
				s_arr[k] = "";
			}
		}
		
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
			
			int last_index = 129;
			for(int k = 1; k <= 490; k++) {
				++last_index;
				
				String n = Integer.toString(k);
				s_arr[last_index] = (obj.get(n) == null) ? "" : obj.get(n).toString();;
			}
			
			
		}
		else {
			int last_index = 129;
			for(int k = 1; k <= 490; k++) {
				++last_index;
				s_arr[last_index] = "";
			}
		}
		
		return s_arr;
	}
	
	public static void AMAG01(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(15);
		JSONObject mdr_obj = null;
		JSONObject pymt_obj = null;
		JSONObject addr_obj = null;
		JSONObject otherinfo_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		if(c_outlet.getOutlet().getPaymentOpt().length() > 0){
			pymt_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getPaymentOpt());
		}
		
		if(c_outlet.getOutlet().getAddress().length() > 0){
			addr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress());
		}
		
		if(c_outlet.getOutlet().getOtherInfo().length() > 0){
			otherinfo_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getOtherInfo());
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "AMAG01";
		System.out.println("*** " + screen_id + " ***");
		
		// Product ID : AMEX_POS
		String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		
		if(in_283 != null && in_283.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("POS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_POS", s_arr);
		}
		
		// Product ID : AMEX_MO
		String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
		
		if(in_284 != null && in_284.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("MO", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_MO", s_arr);
		}
		
		// Product ID : AMEX_E_Commerce
		String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
		
		if(in_287 != null && in_287.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("EC", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
		}
		
		// Product ID : AMEX_RPS
		String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
		
		if(in_286 != null && in_286.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("RPS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_RPS", s_arr);
		}
		
		// Product ID : AMEX_M2U
		String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
		
		if(in_288 != null && in_288.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("M2U", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_M2U", s_arr);
		}
		
		// Product ID : AMEX_L5 / AMEX_L6
		String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		
		if(in_349 != null && in_349.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("L5", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L5", s_arr);
			
			s_arr = AutoScript.AMAG01AmexX("L6", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L6", s_arr);
		}
		
		
		// Product ID : AMEX_E3
		String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
		
		if(in_435 != null && in_435.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("E3", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E3", s_arr);
		}
		
		// Product ID : AMEX_E6
		String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
		
		if(in_436 != null && in_436.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("E6", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E6", s_arr);
		}
		
		// Product ID : AMEX_E9
		String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
		
		if(in_437 != null && in_437.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("E9", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E9", s_arr);
		}
		
		// Product ID : AMEX_E12
		String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
		
		if(in_438 != null && in_438.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("E12", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E12", s_arr);
		}
		
		// Product ID : AMEX_E18
		String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
		
		if(in_439 != null && in_439.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("E18", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E18", s_arr);
		}
		
		// Product ID : AMEX_E24
		String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
		
		if(in_440 != null && in_440.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("E24", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E24", s_arr);
		}
		
		// Product ID : AMEX_E30
		String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
		
		if(in_441 != null && in_441.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("E30", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E30", s_arr);
		}
		
		// Product ID : AMEX_E36
		String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
		
		if(in_442 != null && in_442.length() > 0){
			s_arr = AutoScript.AMAG01AmexX("E36", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E36", s_arr);
		}
	}
	
	public static String[] AMAG01AmexX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject pymt_obj, JSONObject addr_obj, JSONObject otherinfo_obj){
		String[] s_arr = AutoScript.init_arr(15);
		String in_agreement_code = "";
		String in_mcc = "";
		String in_industry_code = "";
		
		if(p_type.equals("POS")){
			in_agreement_code = mdr_obj.get("289").toString();	// AMEX POS - Agreement Code
			in_mcc = mdr_obj.get("22").toString();	// VISA MASTER POS - MCC Code
			in_industry_code = mdr_obj.get("313").toString();	// AMEX POS - Industry Code
		} else if(p_type.equals("MO")){
			in_agreement_code = mdr_obj.get("290").toString();	// AMEX MO - Agreement Code
			in_mcc = mdr_obj.get("24").toString();	// VISA MASTER MO - MCC Code
			in_industry_code = mdr_obj.get("314").toString();	// AMEX MO - Industry Code
		} else if(p_type.equals("EC")){
			in_agreement_code = mdr_obj.get("293").toString();	// AMEX E-Commerce - Agreement Code
			in_mcc = mdr_obj.get("27").toString();	// VISA MASTER EC - MCC Code
			in_industry_code = mdr_obj.get("317").toString();	// AMEX E-Commerce - Industry Code
		} else if(p_type.equals("RPS")){
			in_agreement_code = mdr_obj.get("292").toString();	// AMEX RPS - Agreement Code
			in_mcc = mdr_obj.get("26").toString();	// VISA MASTER RPS - MCC Code
			in_industry_code = mdr_obj.get("316").toString();	// AMEX RPS - Industry Code
		} else if(p_type.equals("M2U")){
			in_agreement_code = mdr_obj.get("294").toString();	// AMEX M2U - Agreement Code
			in_mcc = mdr_obj.get("28").toString();	// VISA MASTER M2U - MCC Code
			in_industry_code = mdr_obj.get("318").toString();	// AMEX RPS - Industry Code
		} else if(p_type.equals("L5")){
			in_agreement_code = "MST01";
			in_mcc = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
			in_industry_code = mdr_obj.get("367").toString();	// AMEX L5/L6 - Industry Code
		} else if(p_type.equals("L6")){
			in_agreement_code = "MST01";
			in_mcc = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
			in_industry_code = mdr_obj.get("367").toString();	// AMEX L5/L6 - Industry Code
		} else if(p_type.equals("E3")){
			in_agreement_code = mdr_obj.get("379").toString();	// AMEX E3 - Agreement Code
			in_mcc = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
			in_industry_code = mdr_obj.get("387").toString();	// AMEX E3 - Industry Code
		} else if(p_type.equals("E6")){
			in_agreement_code = mdr_obj.get("380").toString();	// AMEX E6 - Agreement Code
			in_mcc = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
			in_industry_code = mdr_obj.get("388").toString();	// AMEX E6 - Industry Code
		} else if(p_type.equals("E9")){
			in_agreement_code = mdr_obj.get("381").toString();	// AMEX E9 - Agreement Code
			in_mcc = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
			in_industry_code = mdr_obj.get("389").toString();	// AMEX E9 - Industry Code
		} else if(p_type.equals("E12")){
			in_agreement_code = mdr_obj.get("382").toString();	// AMEX E12 - Agreement Code
			in_mcc = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
			in_industry_code = mdr_obj.get("390").toString();	// AMEX E12 - Industry Code
		} else if(p_type.equals("E18")){
			in_agreement_code = mdr_obj.get("383").toString();	// AMEX E18 - Agreement Code
			in_mcc = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
			in_industry_code = mdr_obj.get("391").toString();	// AMEX E18 - Industry Code
		} else if(p_type.equals("E24")){
			in_agreement_code = mdr_obj.get("384").toString();	// AMEX E24 - Agreement Code
			in_mcc = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
			in_industry_code = mdr_obj.get("392").toString();	// AMEX E24 - Industry Code
		} else if(p_type.equals("E30")){
			in_agreement_code = mdr_obj.get("385").toString();	// AMEX E30 - Agreement Code
			in_mcc = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
			in_industry_code = mdr_obj.get("393").toString();	// AMEX E30 - Industry Code
		} else if(p_type.equals("E36")){
			in_agreement_code = mdr_obj.get("386").toString();	// AMEX E36 - Agreement Code
			in_mcc = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
			in_industry_code = mdr_obj.get("394").toString();	// AMEX E36 - Industry Code
		}
		
		
		s_arr[0] = in_agreement_code;
		
		String sales_rep;
		sales_rep = otherinfo_obj == null ? "0" : otherinfo_obj.get("sales_rep").toString();
		
		s_arr[1] = AutoScript.format_int(sales_rep, 6);
		
		
		
		int s_len = 25;
		
		if(p_type.equals("POS") == false){
			s_len = 25 - (p_type.length() + 1);
		}
		
		
		String s = c_outlet.getOutlet().getName();
		if(s.length() > s_len){
			s = s.substring(0, s_len);
		}
		
		if(p_type.equals("POS")){
			s_arr[2] = s;
		} else if(p_type.equals("E3") || p_type.equals("E6") || p_type.equals("E9") || p_type.equals("E12") || p_type.equals("E18") || p_type.equals("E24") || p_type.equals("E30") || p_type.equals("E36")){
			s_arr[2] = s + "*" + p_type;
		} else {
			s_arr[2] = s + "-" + p_type;
		}
		
		
		s_arr[3] = in_mcc;
		s_arr[4] = in_industry_code;
		
		if(addr_obj != null){
			String addr = addr_obj.get("line_1").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[5] = addr;
			
			addr = addr_obj.get("line_2").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[6] = addr;
			
			addr = addr_obj.get("line_3").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[7] = addr;
			
			addr = addr_obj.get("line_4").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[8] = addr;
			
			addr = addr_obj.get("city").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[9] = addr;
			
			s_arr[10] = addr_obj.get("region_code").toString();
		}
		
		s_arr[11] = c_outlet.getOutlet().getCTFax();
		
		
		if(p_type.equals("L5") || p_type.equals("L6")){
			s_arr[12] = "001";
		}
		else {
			if(pymt_obj != null){
				s_arr[12] = pymt_obj.get("amex_8").toString();
			}
		}
		
		
		if(addr_obj != null){
			String addr = addr_obj.get("postal_code").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[13] = addr;
		}
		
		
		s_arr[14] = c.getCountryCode();
		
		return s_arr;
	}
	
	public static void PCMA01(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(45);
		JSONObject mdr_obj = null;
		JSONObject pymt_obj = null;
		JSONObject addr_obj = null;
		JSONObject otherinfo_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		if(c_outlet.getOutlet().getPaymentOpt().length() > 0){
			pymt_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getPaymentOpt());
		}
		
		if(c_outlet.getOutlet().getAddress().length() > 0){
			addr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress());
		}
		
		if(c_outlet.getOutlet().getOtherInfo().length() > 0){
			otherinfo_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getOtherInfo());
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "PCAM01";
		System.out.println("*** " + screen_id + " ***");
		
		// Product ID : Visa_POS
		String in_22 = mdr_obj.get("22").toString();	// VISA MASTER POS - MCC Code
		
		if(in_22 != null && in_22.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("POS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_POS", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_POS", s_arr);
			}
		}
		
		
		// Product ID : Visa_M2U
		if(c.getCountryCode().equals("MY")){
			String in_28 = mdr_obj.get("28").toString();	// VISA MASTER M2U - MCC Code
			
			if(in_28 != null && in_28.length() > 0){
				s_arr = AutoScript.PCMA01VisaX("M2U", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_M2U", s_arr);
			}
		}
		
		
		// Product ID : Visa_E_Commerce
		String in_27 = mdr_obj.get("27").toString();	// VISA MASTER E-Commerce - MCC Code
		
		if(in_27 != null && in_27.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("EC", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E_Commerce", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E_Commerce", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_RPS
			String in_26 = mdr_obj.get("26").toString();	// VISA MASTER RPS - MCC Code
			
			if(in_26 != null && in_26.length() > 0){
				s_arr = AutoScript.PCMA01VisaX("RPS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_RPS", s_arr);
			}
		}
		
		
		// Product ID : Visa_MO
		String in_24 = mdr_obj.get("24").toString();	// VISA MASTER MO - MCC Code
		
		if(in_24 != null && in_24.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("MO", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_MOTO", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_MO", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_TO
			String in_25 = mdr_obj.get("25").toString();	// VISA MASTER TO - MCC Code
			
			if(in_25 != null && in_25.length() > 0){
				s_arr = AutoScript.PCMA01VisaX("TO", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_TO", s_arr);
			}
		
		
			// Product ID : Visa_ORS
			String in_29 = mdr_obj.get("29").toString();	// VISA MASTER ORS - MCC Code
			
			if(in_29 != null && in_29.length() > 0){
				s_arr = AutoScript.PCMA01VisaX("ORS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_ORS", s_arr);
			}
			
			
			// Product ID : Visa_DCC
			String in_23 = mdr_obj.get("29").toString();	// VISA MASTER DCC - MCC Code
			
			if(in_23 != null && in_23.length() > 0){
				s_arr = AutoScript.PCMA01VisaX("DCC", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_DCC", s_arr);
			}
		}
		
		
		// Product ID : Visa_E3
		String in_190 = mdr_obj.get("190").toString();	// VISA MASTER E3 - MID No Face To Face
		
		if(in_190 != null && in_190.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("E3", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E3", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E3", s_arr);
			}
		}
		
		// Product ID : Visa_E6
		String in_191 = mdr_obj.get("191").toString();	// VISA MASTER E6 - MID No Face To Face
		
		if(in_191 != null && in_191.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("E6", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E6", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E6", s_arr);
			}
		}
		
		// Product ID : Visa_E9
		String in_192 = mdr_obj.get("192").toString();	// VISA MASTER E9 - MID No Face To Face
		
		if(in_192 != null && in_192.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("E9", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E9", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E9", s_arr);
			}
		}
		
		// Product ID : Visa_E12
		String in_193 = mdr_obj.get("193").toString();	// VISA MASTER E12 - MID No Face To Face
		
		if(in_193 != null && in_193.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("E12", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E12", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E12", s_arr);
			}
		}
		
		// Product ID : Visa_E18
		String in_194 = mdr_obj.get("194").toString();	// VISA MASTER E18 - MID No Face To Face
		
		if(in_194 != null && in_194.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("E18", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E18", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E18", s_arr);
			}
		}
		
		// Product ID : Visa_E24
		String in_195 = mdr_obj.get("195").toString();	// VISA MASTER E24 - MID No Face To Face
		
		if(in_195 != null && in_195.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("E24", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E24", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E24", s_arr);
			}
		}
		
		// Product ID : Visa_E30
		String in_196 = mdr_obj.get("196").toString();	// VISA MASTER E30 - MID No Face To Face
		
		if(in_196 != null && in_196.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("E30", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E30", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E30", s_arr);
			}
		}
		
		// Product ID : Visa_E36
		String in_197 = mdr_obj.get("197").toString();	// VISA MASTER E36 - MID No Face To Face
		
		if(in_197 != null && in_197.length() > 0){
			s_arr = AutoScript.PCMA01VisaX("E36", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E36", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E36", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : AMEX_POS
			String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
			
			if(in_283 != null && in_283.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("POS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_POS", s_arr);
			}
			
			// Product ID : AMEX_MO
			String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
			
			if(in_284 != null && in_284.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("MO", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_MO", s_arr);
			}
			
			// Product ID : AMEX_E_Commerce
			String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
			
			if(in_287 != null && in_287.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("EC", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
			}
			
			// Product ID : AMEX_RPS
			String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
			
			if(in_286 != null && in_286.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("RPS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_RPS", s_arr);
			}
			
			// Product ID : AMEX_M2U
			String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
			
			if(in_288 != null && in_288.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("M2U", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_M2U", s_arr);
			}
			
			// Product ID : AMEX_L5 / AMEX_L6
			String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
			
			if(in_349 != null && in_349.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("L5", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L5", s_arr);
				
				s_arr = AutoScript.PCMA01AmexX("L6", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L6", s_arr);
			}
			
			
			// Product ID : AMEX_E3
			String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
			
			if(in_435 != null && in_435.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("E3", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E3", s_arr);
			}
			
			// Product ID : AMEX_E6
			String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
			
			if(in_436 != null && in_436.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("E6", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E6", s_arr);
			}
			
			// Product ID : AMEX_E9
			String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
			
			if(in_437 != null && in_437.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("E9", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E9", s_arr);
			}
			
			// Product ID : AMEX_E12
			String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
			
			if(in_438 != null && in_438.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("E12", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E12", s_arr);
			}
			
			// Product ID : AMEX_E18
			String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
			
			if(in_439 != null && in_439.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("E18", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E18", s_arr);
			}
			
			// Product ID : AMEX_E24
			String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
			
			if(in_440 != null && in_440.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("E24", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E24", s_arr);
			}
			
			// Product ID : AMEX_E30
			String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
			
			if(in_441 != null && in_441.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("E30", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E30", s_arr);
			}
			
			// Product ID : AMEX_E36
			String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
			
			if(in_442 != null && in_442.length() > 0){
				s_arr = AutoScript.PCMA01AmexX("E36", c, c_outlet, mdr_obj, pymt_obj, addr_obj, otherinfo_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E36", s_arr);
			} 
		
		}
		
		return;
	}
	
	public static String[] PCMA01AmexX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject pymt_obj, JSONObject addr_obj, JSONObject otherinfo_obj){
		String[] s_arr = AutoScript.init_arr(45);
		
		String amex_1 = "";
		String amex_2 = "";
		String union_pay_1 = "";
		
		if(pymt_obj != null){
			amex_1 = pymt_obj.get("amex_1").toString();
			amex_2 = pymt_obj.get("amex_2").toString();
			union_pay_1 = pymt_obj.get("union_pay_1").toString();
		}
		
		String in_3 = mdr_obj.get("3").toString();	// VISA MASTER CHAIN STORE HQ MID
		String in_merchant_type = "";
		String in_mcc = "";
		String in_ez_plan_no = "";
		String in_ez_sales = "";
		
		if(p_type.equals("POS")){
			in_merchant_type = mdr_obj.get("271").toString();	// AMEX POS - Merchant Type
			in_mcc = mdr_obj.get("22").toString();	// Visa Master POS - MCC Code
		} else if(p_type.equals("MO")){
			in_merchant_type = mdr_obj.get("272").toString();	// AMEX MO - Merchant Type
			in_mcc = mdr_obj.get("24").toString();	// Visa Master MO - MCC Code
		} else if(p_type.equals("EC")){
			in_merchant_type = mdr_obj.get("275").toString();	// AMEX E-Commerce - Merchant Type
			in_mcc = mdr_obj.get("27").toString();	// Visa Master E-Commerce - MCC Code
		} else if(p_type.equals("RPS")){
			in_merchant_type = mdr_obj.get("274").toString();	// AMEX RPS - Merchant Type
			in_mcc = mdr_obj.get("26").toString();	// Visa Master RPS - MCC Code
		} else if(p_type.equals("M2U")){
			in_merchant_type = mdr_obj.get("276").toString();	// AMEX M2U - Merchant Type
			in_mcc = mdr_obj.get("28").toString();	// Visa Master M2U - MCC Code
		} else if(p_type.equals("L5")){
			in_merchant_type = mdr_obj.get("331").toString();	// AMEX L5/L6 - Merchant Type
			in_mcc = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		} else if(p_type.equals("L6")){
			in_merchant_type = mdr_obj.get("331").toString();	// AMEX L5/L6 - Merchant Type
			in_mcc = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		} else if(p_type.equals("E3")){
			in_merchant_type = mdr_obj.get("403").toString();	// AMEX E3 - Merchant Type
			in_mcc = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
			in_ez_plan_no = mdr_obj.get("443").toString();	// AMEX E3 - Plan No
			in_ez_sales = mdr_obj.get("483").toString();	// AMEX E3 - Monthly Sales Volume
		} else if(p_type.equals("E6")){
			in_merchant_type = mdr_obj.get("404").toString();	// AMEX E6 - Merchant Type
			in_mcc = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
			in_ez_plan_no = mdr_obj.get("444").toString();	// AMEX E6 - Plan No
			in_ez_sales = mdr_obj.get("484").toString();	// AMEX E6 - Monthly Sales Volume
		} else if(p_type.equals("E9")){
			in_merchant_type = mdr_obj.get("405").toString();	// AMEX E9 - Merchant Type
			in_mcc = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
			in_ez_plan_no = mdr_obj.get("445").toString();	// AMEX E9 - Plan No
			in_ez_sales = mdr_obj.get("485").toString();	// AMEX E9 - Monthly Sales Volume
		} else if(p_type.equals("E12")){
			in_merchant_type = mdr_obj.get("406").toString();	// AMEX E12 - Merchant Type
			in_mcc = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
			in_ez_plan_no = mdr_obj.get("446").toString();	// AMEX E12 - Plan No
			in_ez_sales = mdr_obj.get("486").toString();	// AMEX E12 - Monthly Sales Volume
		} else if(p_type.equals("E18")){
			in_merchant_type = mdr_obj.get("407").toString();	// AMEX E18 - Merchant Type
			in_mcc = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
			in_ez_plan_no = mdr_obj.get("447").toString();	// AMEX E18 - Plan No
			in_ez_sales = mdr_obj.get("487").toString();	// AMEX E18 - Monthly Sales Volume
		} else if(p_type.equals("E24")){
			in_merchant_type = mdr_obj.get("408").toString();	// AMEX E24 - Merchant Type
			in_mcc = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
			in_ez_plan_no = mdr_obj.get("448").toString();	// AMEX E24 - Plan No
			in_ez_sales = mdr_obj.get("488").toString();	// AMEX E24 - Monthly Sales Volume
		} else if(p_type.equals("E30")){
			in_merchant_type = mdr_obj.get("409").toString();	// AMEX E30 - Merchant Type
			in_mcc = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
			in_ez_plan_no = mdr_obj.get("449").toString();	// AMEX E30 - Plan No
			in_ez_sales = mdr_obj.get("489").toString();	// AMEX E30 - Monthly Sales Volume
		} else if(p_type.equals("E36")){
			in_merchant_type = mdr_obj.get("410").toString();	// AMEX E36 - Merchant Type
			in_mcc = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
			in_ez_plan_no = mdr_obj.get("450").toString();	// AMEX E36 - Plan No
			in_ez_sales = mdr_obj.get("490").toString();	// AMEX E36 - Monthly Sales Volume
		}
		
		
		s_arr[0] = "00";
		s_arr[1] = "00";
		s_arr[2] = "00";
		s_arr[3] = "00";
		
		
		String s = c_outlet.getOutlet().getName();
		int s_len = 25;
		
		if(p_type.equals("POS")){
			if(s.length() > s_len){
				s = s.substring(0, s_len);
			}
			
			s_arr[4] = s;
			
		} else {
			
			s_len = 25 - (p_type.length() + 1);
			if(s.length() > s_len){
				s = s.substring(0, s_len);
			}
			
			if(p_type.equals("E3") || p_type.equals("E6") || p_type.equals("E9") || p_type.equals("E12") || p_type.equals("E18") || p_type.equals("E24") || p_type.equals("E30") || p_type.equals("E36")){
				s_arr[4] = s + "*" + p_type;
			} else {
				s_arr[4] = s + "-" + p_type;
			}
		}
		
		s_arr[5] = AutoScript.today_date(AutoScript.date_format);
		
		if(addr_obj != null){
			String addr = addr_obj.get("city").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[6] = addr;
		}
		
		
		s_arr[7] = c.getCountryCode();
		s_arr[8] = c_outlet.getOutlet().getCTName();
		
		
		if(p_type.equals("E3") || p_type.equals("E6") || p_type.equals("E9") || p_type.equals("E12") || p_type.equals("E18") || p_type.equals("E24") || p_type.equals("E30") || p_type.equals("E36")){
			if(amex_1.equals("credit_maybank")){
				s_arr[9] = "02700000";
			} else {
				s_arr[9] = "0000000000000000000";
			}
		} 
		else if(p_type.equals("L5") || p_type.equals("L6")){
			s_arr[9] = "0000000000000000000";
		} 
		else {
			if(amex_1.equals("credit_maybank")){
				s_arr[9] = "027000000000";
			} else {
				s_arr[9] = "0000000000000000000";
			}
		}
		
		
		s_arr[10] = c_outlet.getOutlet().getCTTel();
		
		if(otherinfo_obj != null){
			s_arr[11] = otherinfo_obj.get("officer_code").toString();
		}
		
		if(p_type.equals("L5") || p_type.equals("L6")){
			s_arr[12] = "010000000000";
		} else {
			s_arr[12] = amex_2;
		}
		
		s_arr[13] = in_merchant_type;
		s_arr[14] = "000000000";
		
		
		s_arr[15] = " ";
		s_arr[16] = c_outlet.getOutlet().getMerchant().getRegisteredName();
		
		if(addr_obj != null){
			String addr = addr_obj.get("line_1").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[17] = addr;
			
			addr = addr_obj.get("line_2").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[18] = addr;
			
			addr = addr_obj.get("line_3").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[19] = addr;
			
			addr = addr_obj.get("line_4").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[20] = addr;
			
			s_arr[21] = addr_obj.get("postal_code").toString();
		}
		
		s_arr[22] = "0000";
		s_arr[23] = "0000";
		s_arr[24] = "0000";
		s_arr[25] = in_mcc;
		s_arr[26] = "0000";
		
		if(p_type.equals("POS") || p_type.equals("MO") || p_type.equals("EC") || p_type.equals("RPS") || p_type.equals("M2U")){
			s_arr[27] = otherinfo_obj.get("chain_merchant").toString();
			s_arr[28] = otherinfo_obj.get("hierarchy_no").toString();
			
		} else if(p_type.equals("L5") || p_type.equals("L6")){
			s_arr[27] = mdr_obj.get("337").toString();	// AMEX L5/L6 - Mid No L5 Ezypay#
			s_arr[28] = mdr_obj.get("270").toString();	// AMEX HIERARCHY NO (EZYPAY)
		} else {
			s_arr[27] = mdr_obj.get("343").toString();	// AMEX L5/L6 - Mid No L6 Ezypay#
			s_arr[28] = mdr_obj.get("270").toString();	// AMEX HIERARCHY NO (EZYPAY)
		}
		
		
		if(p_type.equals("POS") || p_type.equals("MO") || p_type.equals("EC") || p_type.equals("RPS") || p_type.equals("M2U")){
			s_arr[29] = otherinfo_obj.get("level").toString();
		} else if(p_type.equals("L5")){
			s_arr[29] = "5";
		} else if(p_type.equals("L6")){
			s_arr[29] = "6";
		} else {
			s_arr[29] = "9";
		}
		
		s_arr[30] = "0000";
		s_arr[31] = "0000";
		s_arr[32] = "0000";
		
		if(p_type.equals("POS") || p_type.equals("MO") || p_type.equals("EC") || p_type.equals("RPS") || p_type.equals("M2U") || p_type.equals("L5") || p_type.equals("L6")){
			s_arr[33] = "0000";
		} else {
			s_arr[33] = in_ez_plan_no;
		}
		
		s_arr[34] = "0000";
		s_arr[35] = "0000";
		s_arr[36] = "00";
		s_arr[37] = "00";
		s_arr[38] = "00";
		
		Date d1 = new Date();
		Date d2 = null;
		
		if(c_outlet.getOutlet().getRiskLevel() == "hi"){
			d2 = new Date(d1.getTime() + (1 * 365 * 24 * 60 * 60 * AutoScript.ms));
			s_arr[39] = AutoScript.today_date("ddMMyy", d2);
		} else if(c_outlet.getOutlet().getRiskLevel() == "me"){
			d2 = new Date(d1.getTime() + (2 * 365 * 24 * 60 * 60 * AutoScript.ms));
			s_arr[39] = AutoScript.today_date("ddMMyy", d2);
		} else {
			s_arr[39] = "000000";
		}
		
		s_arr[40] = "";
		s_arr[41] = "";
		
		if(otherinfo_obj != null){
			s_arr[42] = otherinfo_obj.get("user_code_3").toString();
		}
		
		
		if(p_type.equals("POS") || p_type.equals("MO") || p_type.equals("EC") || p_type.equals("RPS") || p_type.equals("M2U") || p_type.equals("L5") || p_type.equals("L6")){
			s_arr[43] = "00000";
			s_arr[44] = "0000000000";
		} else {
			s_arr[43] = "00000";
			s_arr[44] = in_ez_sales;
		}
		
		
		return s_arr;
	}
	
	public static String[] PCMA01VisaX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject pymt_obj, JSONObject addr_obj, JSONObject otherinfo_obj){
		String[] s_arr = AutoScript.init_arr(45);
		
		String visa_2 = "";
		String visa_6 = "";
		String ezypay_1 = "";
		String union_pay_1 = "";
		String mbb_phi_1 = "";
		
		if(pymt_obj != null){
			visa_2 = pymt_obj.get("visa_2").toString();
			visa_6 = pymt_obj.get("visa_6").toString();
			ezypay_1 = pymt_obj.get("ezypay_1").toString();
			union_pay_1 = pymt_obj.get("union_pay_1").toString();
			mbb_phi_1 = pymt_obj.get("mbb_phi_1").toString();
		}
		
		
		String in_3 = mdr_obj.get("3").toString();	// VISA MASTER CHAIN STORE HQ MID
		String in_mtype = "";
		String in_mcc = "";
		String in_visa_onus = "";
		String in_visa_offus = "";
		String in_master_onus = "";
		String in_master_offus = "";
		String in_eftpos_atm = "";
		String in_mep_epos = "";
		String in_maestro = "";
		String in_jcb = "";
		String in_ez_plan = "";
		String in_ez_ticketsize = "";
		String in_ez_salesvol = "";
		
		if(p_type.equals("POS")){
			in_mtype = mdr_obj.get("6").toString();  // VISA MASTER POS - Merchant Type
			in_mcc = mdr_obj.get("22").toString();	// VISA MASTER POS - MCC Code
			in_visa_onus = mdr_obj.get("30").toString();	// VISA MASTER POS - Visa OnUs
			in_visa_offus = mdr_obj.get("38").toString();	// VISA MASTER POS - Visa OffUs
			in_master_onus = mdr_obj.get("46").toString();	// VISA MASTER POS - Master OnUs
			in_master_offus = mdr_obj.get("54").toString();	// VISA MASTER POS - Master OffUs
			in_eftpos_atm = mdr_obj.get("78").toString();	// VISA MASTER POS - EFTPOS-ATM
			in_mep_epos = mdr_obj.get("86").toString();	// VISA MASTER POS - MEPS EPOS
			in_maestro = mdr_obj.get("94").toString();	// VISA MASTER POS - MAESTRO
			in_jcb = mdr_obj.get("102").toString();	// VISA MASTER POS - JCB
		} else if(p_type.equals("M2U")){
			in_mtype = mdr_obj.get("12").toString();  // VISA MASTER M2U - Merchant Type
			in_mcc = mdr_obj.get("28").toString();	// VISA MASTER M2U - MCC Code
		} else if(p_type.equals("EC")) {
			in_mtype = mdr_obj.get("11").toString();  // VISA MASTER E-Commerce - Merchant Type
			in_mcc = mdr_obj.get("27").toString();	// VISA MASTER E-Commerce - MCC Code
		} else if(p_type.equals("RPS")){
			in_mtype = mdr_obj.get("10").toString();  // VISA MASTER RPS - Merchant Type
			in_mcc = mdr_obj.get("26").toString();	// VISA MASTER RPS - MCC Code
		} else if(p_type.equals("MO") || p_type.equals("MOTO")){
			in_mtype = mdr_obj.get("8").toString();  // VISA MASTER MO - Merchant Type
			in_mcc = mdr_obj.get("24").toString();	// VISA MASTER MO - MCC Code
		} else if(p_type.equals("TO")){
			in_mtype = mdr_obj.get("9").toString();  // VISA MASTER TO - Merchant Type
			in_mcc = mdr_obj.get("25").toString();	// VISA MASTER TO - MCC Code
		} else if(p_type.equals("ORS")){
			in_mtype = mdr_obj.get("13").toString();  // VISA MASTER ORS - Merchant Type
			in_mcc = mdr_obj.get("29").toString();	// VISA MASTER ORS - MCC Code
		} else if(p_type.equals("DCC")){
			in_mtype = mdr_obj.get("7").toString();  // VISA MASTER DCC - Merchant Type
			in_mcc = mdr_obj.get("23").toString();	// VISA MASTER DCC - MCC Code
		} else if(p_type.equals("E3")){
			in_mtype = mdr_obj.get("182").toString();  // VISA MASTER E3 - Merchant Type
			in_mcc = mdr_obj.get("214").toString();	// VISA MASTER E3 - MCC Code
			in_ez_plan = mdr_obj.get("222").toString();	// VISA MASTER E3 - Plan No
			in_ez_ticketsize = mdr_obj.get("254").toString();	// VISA MASTER E3 - Ticket Size
			in_ez_salesvol = mdr_obj.get("262").toString();	// VISA MASTER E3 - Monthly Sales Volume
		} else if(p_type.equals("E6")){
			in_mtype = mdr_obj.get("183").toString();  // VISA MASTER E6 - Merchant Type
			in_mcc = mdr_obj.get("215").toString();	// VISA MASTER E6 - MCC Code
			in_ez_plan = mdr_obj.get("223").toString();	// VISA MASTER E6 - Plan No
			in_ez_ticketsize = mdr_obj.get("255").toString();	// VISA MASTER E6 - Ticket Size
			in_ez_salesvol = mdr_obj.get("263").toString();	// VISA MASTER E6 - Monthly Sales Volume
		} else if(p_type.equals("E9")){
			in_mtype = mdr_obj.get("184").toString();  // VISA MASTER E9 - Merchant Type
			in_mcc = mdr_obj.get("216").toString();	// VISA MASTER E9 - MCC Code
			in_ez_plan = mdr_obj.get("224").toString();	// VISA MASTER E9 - Plan No
			in_ez_ticketsize = mdr_obj.get("256").toString();	// VISA MASTER E9 - Ticket Size
			in_ez_salesvol = mdr_obj.get("264").toString();	// VISA MASTER E9 - Monthly Sales Volume
		} else if(p_type.equals("E12")){
			in_mtype = mdr_obj.get("185").toString();  // VISA MASTER E12 - Merchant Type
			in_mcc = mdr_obj.get("217").toString();	// VISA MASTER E12 - MCC Code
			in_ez_plan = mdr_obj.get("225").toString();	// VISA MASTER E12 - Plan No
			in_ez_ticketsize = mdr_obj.get("257").toString();	// VISA MASTER E12 - Ticket Size
			in_ez_salesvol = mdr_obj.get("265").toString();	// VISA MASTER E12 - Monthly Sales Volume
		} else if(p_type.equals("E18")){
			in_mtype = mdr_obj.get("186").toString();  // VISA MASTER E18 - Merchant Type
			in_mcc = mdr_obj.get("218").toString();	// VISA MASTER E18 - MCC Code
			in_ez_plan = mdr_obj.get("226").toString();	// VISA MASTER E18 - Plan No
			in_ez_ticketsize = mdr_obj.get("258").toString();	// VISA MASTER E18 - Ticket Size
			in_ez_salesvol = mdr_obj.get("266").toString();	// VISA MASTER E18 - Monthly Sales Volume
		} else if(p_type.equals("E24")){
			in_mtype = mdr_obj.get("187").toString();  // VISA MASTER E24 - Merchant Type
			in_mcc = mdr_obj.get("219").toString();	// VISA MASTER E24 - MCC Code
			in_ez_plan = mdr_obj.get("227").toString();	// VISA MASTER E24 - Plan No
			in_ez_ticketsize = mdr_obj.get("259").toString();	// VISA MASTER E24 - Ticket Size
			in_ez_salesvol = mdr_obj.get("267").toString();	// VISA MASTER E24 - Monthly Sales Volume
		} else if(p_type.equals("E30")){
			in_mtype = mdr_obj.get("188").toString();  // VISA MASTER E30 - Merchant Type
			in_mcc = mdr_obj.get("220").toString();	// VISA MASTER E30 - MCC Code
			in_ez_plan = mdr_obj.get("228").toString();	// VISA MASTER E30 - Plan No
			in_ez_ticketsize = mdr_obj.get("260").toString();	// VISA MASTER E30 - Ticket Size
			in_ez_salesvol = mdr_obj.get("268").toString();	// VISA MASTER E30 - Monthly Sales Volume
		} else if(p_type.equals("E36")){
			in_mtype = mdr_obj.get("189").toString();  // VISA MASTER E36 - Merchant Type
			in_mcc = mdr_obj.get("221").toString();	// VISA MASTER E36 - MCC Code
			in_ez_plan = mdr_obj.get("229").toString();	// VISA MASTER E36 - Plan No
			in_ez_ticketsize = mdr_obj.get("261").toString();	// VISA MASTER E36 - Ticket Size
			in_ez_salesvol = mdr_obj.get("269").toString();	// VISA MASTER E36 - Monthly Sales Volume
		}
		
		
		if(p_type.equals("POS") || p_type.equals("RPS") || p_type.equals("MO") || p_type.equals("MOTO") || p_type.equals("TO")){
			s_arr[0] = c_outlet.getNumTerminal();
			s_arr[1] = c_outlet.getTrmRental();
			s_arr[2] = c_outlet.getTrmOwner();
		} else {
			s_arr[0] = "00";
			s_arr[1] = "00";
			s_arr[2] = "00";
		}
		
		
		String s = c_outlet.getOutlet().getName();
		int s_len = 25;
		
		if(p_type.equals("POS")){
			if(c.getCountryCode().equals("PH")){
				s_arr[3] = "00";
			} 
			else {
				if(union_pay_1.equals("credit_maybank")){
					s_arr[3] = "01";
				} else if(union_pay_1.equals("interbank_giro")) {
					s_arr[3] = "02";
				} else {
					s_arr[3] = "00";
				}
			}
			
			if(s.length() > s_len){
				s = s.substring(0, s_len);
			}
			s_arr[4] = s;
			
		} else {
			s_arr[3] = "00";
			
			s_len = 25 - (p_type.length() + 1);
			
			if(s.length() > s_len){
				s = s.substring(0, s_len);
			}
			
			s_arr[4] = s + "-" + p_type;
		}
		
		
		s_arr[5] = AutoScript.today_date(AutoScript.date_format);
		
		if(addr_obj != null){
			String addr = addr_obj.get("city").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[6] = addr;
		}
		
		s_arr[7] = c.getCountryCode();
		s_arr[8] = c_outlet.getOutlet().getCTName();
		
		if(c.getCountryCode().equals("PH")){
			if(p_type.equals("EC")){
				s_arr[9] = mbb_phi_1;
			}
			else {
				s_arr[9] = "10100000";
			}
		}
		else {
			if(p_type.equals("EC") || p_type.equals("E3") || p_type.equals("E6") || p_type.equals("E9") || p_type.equals("E12") || p_type.equals("E18") || p_type.equals("E24") || p_type.equals("E30") || p_type.equals("E36")){
				s_arr[9] = ezypay_1;
			} else {
				s_arr[9] = visa_6;
			}
		}
		
		s_arr[10] = c_outlet.getOutlet().getCTTel();
		
		if(otherinfo_obj != null){
			s_arr[11] = otherinfo_obj.get("officer_code").toString();
		}
		
		s_arr[12] = visa_2;
		s_arr[13] = in_mtype;
		s_arr[14] = in_3;
		s_arr[15] = "";
		s_arr[16] = c_outlet.getOutlet().getMerchant().getRegisteredName();
		
		if(addr_obj != null){
			String addr = addr_obj.get("line_1").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[17] = addr;
			
			addr = addr_obj.get("line_2").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[18] = addr;
			
			addr = addr_obj.get("line_3").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[19] = addr;
			
			addr = addr_obj.get("line_4").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[20] = addr;
			
			s_arr[21] = addr_obj.get("postal_code").toString();
		}
		
		if(p_type.equals("POS")){
			if(in_visa_onus.equals("") && in_visa_offus.equals("")){
				s_arr[22] = "0000";
			} else {
				s_arr[22] = in_mcc;
			}
		}
		else {
			s_arr[22] = in_mcc;
		}
		
		
		if(p_type.equals("POS")){
			if(in_master_onus.equals("") && in_master_offus.equals("")){
				s_arr[23] = "0000";
			} else {
				s_arr[23] = in_mcc;
			}
		}
		else {
			s_arr[23] = in_mcc;
		}
		
		if(p_type.equals("POS")){
			if(c.getCountryCode().equals("PH")){
				s_arr[24] = "0000";
				s_arr[25] = "0000";
				s_arr[26] = "0000";
			}
			else {
				if(in_eftpos_atm.equals("") && in_mep_epos.equals("") && in_maestro.equals("")){
					s_arr[24] = "0000";
				} else {
					s_arr[24] = in_mcc;
				}
				
				s_arr[25] = "0000";
				
				if(in_jcb.equals("") == false){
					s_arr[26] = "0000";
				} else {
					s_arr[26] = in_jcb;
				}
			}
			
		} else if(p_type.equals("M2U")) {
			s_arr[24] = in_mcc;
			s_arr[25] = "0000";
			s_arr[26] = "0000";
			
		} else {
			s_arr[24] = "0000";
			s_arr[25] = "0000";
			s_arr[26] = "0000";
		}
		
		s_arr[27] = "000000000";
		s_arr[28] = "000000000";
		s_arr[29] = "0";
		s_arr[30] = "000";
		s_arr[31] = "000";
		s_arr[32] = "000";
		
		if(p_type.equals("E3") || p_type.equals("E6") || p_type.equals("E9") || p_type.equals("E12") || p_type.equals("E18") || p_type.equals("E24") || p_type.equals("E30") || p_type.equals("E36")){
			s_arr[33] = in_ez_plan;
		} else {
			s_arr[33] = "000";
		}
		
		s_arr[34] = "000";
		s_arr[35] = "000";
		s_arr[36] = "00";
		s_arr[37] = "00";
		s_arr[38] = "00";
		
		Date d1 = new Date();
		Date d2 = null;
		
		if(c_outlet.getOutlet().getRiskLevel() == "hi"){
			d2 = new Date(d1.getTime() + (1 * 365 * 24 * 60 * 60 * AutoScript.ms));
			s_arr[39] = AutoScript.today_date("ddMMyy", d2);
		} else if(c_outlet.getOutlet().getRiskLevel() == "me"){
			d2 = new Date(d1.getTime() + (2 * 365 * 24 * 60 * 60 * AutoScript.ms));
			s_arr[39] = AutoScript.today_date("ddMMyy", d2);
		} else {
			s_arr[39] = "000000";
		}
		
		if(otherinfo_obj != null){
			s_arr[40] = otherinfo_obj.get("user_code_1").toString();
			if(s_arr[40].trim().equals("")){
				s_arr[40] = " ";
			}
			
			s_arr[41] = otherinfo_obj.get("user_code_2").toString();
			s_arr[42] = otherinfo_obj.get("user_code_3").toString();
		}
		
		
		if(p_type.equals("POS") || p_type.equals("M2U") || p_type.equals("EC") || p_type.equals("RPS") || p_type.equals("MO") || p_type.equals("TO")){
			
			s = c.getMerchant().getAvgTicketSize();
			if(s.length() <= 0){
				s = "0";
			}
			
			s_arr[43] = AutoScript.format_int(s, 5);
			s_arr[44] = "000000000";
			
		} else if(p_type.equals("ORS") || p_type.equals("DCC")) {
			s_arr[43] = "00000";
			s_arr[44] = "000000000";
		} else {
			
			if(in_ez_ticketsize.trim().length() > 0){
				in_ez_ticketsize = in_ez_ticketsize.trim();
			} else {
				in_ez_ticketsize = "0";
			}
			
			s_arr[43] = AutoScript.format_int(in_ez_ticketsize, 5);
			
			
			if(in_ez_salesvol.trim().length() > 0){
				in_ez_salesvol = in_ez_salesvol.trim();
			} else {
				in_ez_salesvol = "0";
			}
			
			s_arr[44] = AutoScript.format_int(in_ez_salesvol, 9);
			
		}
		
		return s_arr;
	}
	
	public static void PCMA02(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(19);
		
		JSONObject mdr_obj = null;
		JSONObject pymt_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		if(c_outlet.getOutlet().getPaymentOpt().length() > 0){
			pymt_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getPaymentOpt());
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "PCAM02";
		System.out.println("*** " + screen_id + " ***");
		
		// Product ID : Visa_POS
		String in_22 = mdr_obj.get("22").toString();	// VISA MASTER POS - MCC Code
		
		if(in_22 != null && in_22.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("POS", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_POS", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_POS", s_arr);
			}
		}
		
		
		// Product ID : Visa_M2U
		if(c.getCountryCode().equals("MY")){
			String in_28 = mdr_obj.get("28").toString();	// VISA MASTER M2U - MCC Code
			
			if(in_28 != null && in_28.length() > 0){
				s_arr = AutoScript.PCMA02VisaX("M2U", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_M2U", s_arr);
			}
		}
		
		
		// Product ID : Visa_E_Commerce
		String in_27 = mdr_obj.get("27").toString();	// VISA MASTER E-Commerce - MCC Code
		
		if(in_27 != null && in_27.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("EC", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E_Commerce", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E_Commerce", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_RPS
			String in_26 = mdr_obj.get("26").toString();	// VISA MASTER RPS - MCC Code
			
			if(in_26 != null && in_26.length() > 0){
				s_arr = AutoScript.PCMA02VisaX("RPS", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_RPS", s_arr);
			}
		}
		
		
		// Product ID : Visa_MO
		String in_24 = mdr_obj.get("24").toString();	// VISA MASTER MO - MCC Code
		
		if(in_24 != null && in_24.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("MO", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_MO", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_MO", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_TO
			String in_25 = mdr_obj.get("25").toString();	// VISA MASTER TO - MCC Code
			
			if(in_25 != null && in_25.length() > 0){
				s_arr = AutoScript.PCMA02VisaX("TO", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_TO", s_arr);
			}
			
			// Product ID : Visa_ORS
			String in_29 = mdr_obj.get("29").toString();	// VISA MASTER ORS - MCC Code
			
			if(in_29 != null && in_29.length() > 0){
				s_arr = AutoScript.PCMA02VisaX("ORS", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_ORS", s_arr);
			}
			
			
			// Product ID : Visa_DCC
			String in_23 = mdr_obj.get("29").toString();	// VISA MASTER DCC - MCC Code
			
			if(in_23 != null && in_23.length() > 0){
				s_arr = AutoScript.PCMA02VisaX("DCC", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_DCC", s_arr);
			}
		}
				
		
		// Product ID : Visa_E3
		String in_190 = mdr_obj.get("190").toString();	// VISA MASTER E3 - MID No Face To Face

		if(in_190 != null && in_190.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("E3", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E3", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E3", s_arr);
			}
		}
		
		// Product ID : Visa_E6
		String in_191 = mdr_obj.get("191").toString();	// VISA MASTER E6 - MID No Face To Face

		if(in_191 != null && in_191.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("E6", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E6", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E6", s_arr);
			}
		}
		
		// Product ID : Visa_E9
		String in_192 = mdr_obj.get("192").toString();	// VISA MASTER E9 - MID No Face To Face

		if(in_192 != null && in_192.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("E9", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E9", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E9", s_arr);
			}
		}
		
		// Product ID : Visa_E12
		String in_193 = mdr_obj.get("193").toString();	// VISA MASTER E12 - MID No Face To Face

		if(in_193 != null && in_193.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("E12", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E12", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E12", s_arr);
			}
		}
		
		// Product ID : Visa_E18
		String in_194 = mdr_obj.get("194").toString();	// VISA MASTER E18 - MID No Face To Face

		if(in_194 != null && in_194.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("E18", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E18", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E18", s_arr);
			}
		}
		
		// Product ID : Visa_E24
		String in_195 = mdr_obj.get("195").toString();	// VISA MASTER E24 - MID No Face To Face

		if(in_195 != null && in_195.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("E24", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E24", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E24", s_arr);
			}
		}
		
		// Product ID : Visa_E30
		String in_196 = mdr_obj.get("196").toString();	// VISA MASTER E30 - MID No Face To Face

		if(in_196 != null && in_196.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("E30", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E30", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E30", s_arr);
			}
		}
		
		// Product ID : Visa_E36
		String in_197 = mdr_obj.get("197").toString();	// VISA MASTER E36 - MID No Face To Face

		if(in_197 != null && in_197.length() > 0){
			s_arr = AutoScript.PCMA02VisaX("E36", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E36", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E36", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : AMEX_POS
			String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
			
			if(in_283 != null && in_283.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("POS", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_POS", s_arr);
			}
			
			// Product ID : AMEX_MO
			String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
			
			if(in_284 != null && in_284.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("MO", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_MO", s_arr);
			}
			
			// Product ID : AMEX_E_Commerce
			String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
			
			if(in_287 != null && in_287.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("EC", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
			}
			
			// Product ID : AMEX_RPS
			String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
			
			if(in_286 != null && in_286.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("RPS", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_RPS", s_arr);
			}
			
			// Product ID : AMEX_M2U
			String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
			
			if(in_288 != null && in_288.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("M2U", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_M2U", s_arr);
			}
			
			// Product ID : AMEX_L5 / AMEX_L6
			String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
			
			if(in_349 != null && in_349.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("L5", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L5", s_arr);
				
				s_arr = AutoScript.PCMA02AmexX("L6", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L6", s_arr);
			}
			
			
			// Product ID : AMEX_E3
			String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
			
			if(in_435 != null && in_435.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("E3", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E3", s_arr);
			}
			
			// Product ID : AMEX_E6
			String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
			
			if(in_436 != null && in_436.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("E6", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E6", s_arr);
			}
			
			// Product ID : AMEX_E9
			String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
			
			if(in_437 != null && in_437.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("E9", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E9", s_arr);
			}
			
			// Product ID : AMEX_E12
			String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
			
			if(in_438 != null && in_438.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("E12", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E12", s_arr);
			}
			
			// Product ID : AMEX_E18
			String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
			
			if(in_439 != null && in_439.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("E18", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E18", s_arr);
			}
			
			// Product ID : AMEX_E24
			String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
			
			if(in_440 != null && in_440.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("E24", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E24", s_arr);
			}
			
			// Product ID : AMEX_E30
			String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
			
			if(in_441 != null && in_441.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("E30", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E30", s_arr);
			}
			
			// Product ID : AMEX_E36
			String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
			
			if(in_442 != null && in_442.length() > 0){
				s_arr = AutoScript.PCMA02AmexX("E36", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E36", s_arr);
			} 
		}
		
		return;
	}
	
	public static String[] PCMA02AmexX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject pymt_obj){
		String[] s_arr = AutoScript.init_arr(20);
		
		String amex_1 = "";
		String amex_4 = "";
		String amex_5 = "";
		
		if(pymt_obj != null){
			amex_1 = pymt_obj.get("amex_1").toString();
			amex_4 = pymt_obj.get("amex_4").toString();
			amex_5 = pymt_obj.get("amex_5").toString();
		}
		
		String in_min = "";
		String in_max = "";
		
		if(p_type.equals("E3")){
			in_min = mdr_obj.get("451").toString();	// AMEX E3 - Min Amount
			in_max = mdr_obj.get("459").toString();	// AMEX E3 - Max Amount
		} else if(p_type.equals("E6")){
			in_min = mdr_obj.get("452").toString();	// AMEX E6 - Min Amount
			in_max = mdr_obj.get("460").toString();	// AMEX E6 - Max Amount
		} else if(p_type.equals("E9")){
			in_min = mdr_obj.get("453").toString();	// AMEX E9 - Min Amount
			in_max = mdr_obj.get("461").toString();	// AMEX E9 - Max Amount
		} else if(p_type.equals("E12")){
			in_min = mdr_obj.get("454").toString();	// AMEX E12 - Min Amount
			in_max = mdr_obj.get("462").toString();	// AMEX E12 - Max Amount
		} else if(p_type.equals("E18")){
			in_min = mdr_obj.get("455").toString();	// AMEX E18 - Min Amount
			in_max = mdr_obj.get("463").toString();	// AMEX E18 - Max Amount
		} else if(p_type.equals("E24")){
			in_min = mdr_obj.get("456").toString();	// AMEX E24 - Min Amount
			in_max = mdr_obj.get("464").toString();	// AMEX E24 - Max Amount
		} else if(p_type.equals("E30")){
			in_min = mdr_obj.get("457").toString();	// AMEX E30 - Min Amount
			in_max = mdr_obj.get("465").toString();	// AMEX E30 - Max Amount
		} else if(p_type.equals("E36")){
			in_min = mdr_obj.get("458").toString();	// AMEX E36 - Min Amount
			in_max = mdr_obj.get("466").toString();	// AMEX E36 - Max Amount
		}
		
		
		if(p_type.equals("E3") || p_type.equals("E6") || p_type.equals("E9") || p_type.equals("E12") || p_type.equals("E18") || p_type.equals("E24") || p_type.equals("E30") || p_type.equals("E36")){
			in_min = AutoScript.format_int(in_min, 9);
			in_max = AutoScript.format_int(in_max, 9);
			
			s_arr[0] = in_min + in_max;
			
		} else {
			s_arr[0] = "000000500000010000";
		}
		
		
		if(p_type.equals("L5") || p_type.equals("L6")){
			s_arr[1] = "0000";
		} else {
			if(amex_1.equals("credit_maybank")){
				s_arr[1] = "02001";
			} else if(amex_1.equals("interbank_giro")){
				s_arr[1] = amex_4;
			} else if(amex_1.equals("banker_cheque")){
				s_arr[1] = amex_5;
			}
			
		}
		
		
		s_arr[2] = "00000";
		s_arr[3] = "999999999";
		s_arr[4] = "0";
		s_arr[5] = "0";
		s_arr[6] = "4";
		s_arr[7] = "1";
		s_arr[8] = "0";
		s_arr[9] = "0";
		s_arr[10] = "0";
		s_arr[11] = "0";
		s_arr[12] = "0";
		s_arr[13] = "0";
		s_arr[14] = "0";
		s_arr[15] = "0";
		s_arr[16] = "0";
		s_arr[17] = "030";
		s_arr[18] = "0";
		s_arr[19] = "0";
		
		return s_arr;
	}
	
	public static String[] PCMA02VisaX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject pymt_obj){
		String[] s_arr = AutoScript.init_arr(19);
		
		String visa_1 = "";
		String visa_7 = "";
		
		if(pymt_obj != null){
			visa_1 = pymt_obj.get("visa_1").toString();
			visa_7 = pymt_obj.get("visa_7").toString();
		}
		
		String in_min = "";
		String in_max = "";
		
		if(p_type.equals("E3")){
			in_min = mdr_obj.get("230").toString();	// VISA MASTER E3 - Min Amount
			in_max = mdr_obj.get("238").toString();	// VISA MASTER E3 - Max Amount
		} else if(p_type.equals("E6")){
			in_min = mdr_obj.get("231").toString();	// VISA MASTER E6 - Min Amount
			in_max = mdr_obj.get("239").toString();	// VISA MASTER E6 - Max Amount
		} else if(p_type.equals("E9")){
			in_min = mdr_obj.get("232").toString();	// VISA MASTER E9 - Min Amount
			in_max = mdr_obj.get("240").toString();	// VISA MASTER E9 - Max Amount
		} else if(p_type.equals("E12")){
			in_min = mdr_obj.get("233").toString();	// VISA MASTER E12 - Min Amount
			in_max = mdr_obj.get("241").toString();	// VISA MASTER E12 - Max Amount
		} else if(p_type.equals("E18")){
			in_min = mdr_obj.get("234").toString();	// VISA MASTER E18 - Min Amount
			in_max = mdr_obj.get("242").toString();	// VISA MASTER E18 - Max Amount
		} else if(p_type.equals("E24")){
			in_min = mdr_obj.get("235").toString();	// VISA MASTER E24 - Min Amount
			in_max = mdr_obj.get("243").toString();	// VISA MASTER E24 - Max Amount
		} else if(p_type.equals("E30")){
			in_min = mdr_obj.get("236").toString();	// VISA MASTER E30 - Min Amount
			in_max = mdr_obj.get("244").toString();	// VISA MASTER E30 - Max Amount
		} else if(p_type.equals("E36")){
			in_min = mdr_obj.get("237").toString();	// VISA MASTER E36 - Min Amount
			in_max = mdr_obj.get("245").toString();	// VISA MASTER E36 - Max Amount
		}
		
		
		if(p_type.equals("E3") || p_type.equals("E6") || p_type.equals("E9") || p_type.equals("E12") || p_type.equals("E18") || p_type.equals("E24") || p_type.equals("E30") || p_type.equals("E36")){
			in_min = AutoScript.format_int(in_min, 9);
			in_max = AutoScript.format_int(in_max, 9);
			
			s_arr[0] = in_min + in_max;
		} else {
			s_arr[0] = "000000500000100000";
		}
		
		
		s_arr[1] = "0000";
		
		
		if(c.getCountryCode().equals("PH")){
			s_arr[2] = "00000";
		} 
		else {
			if(p_type.equals("POS") || p_type.equals("M2U") || p_type.equals("RPS") || p_type.equals("MO") || p_type.equals("TO") || p_type.equals("ORS") || p_type.equals("DCC")){
				s_arr[2] = visa_7;
			} else {
				s_arr[2] = "00000";
			}
		}
		
		
		if(visa_1.equals("credit_maybank")){
			s_arr[3] = "999999999";
		} else {
			s_arr[3] = "000000000";
		}
		
		
		s_arr[4] = "0";
		s_arr[5] = "0";
		s_arr[6] = "1";
		s_arr[7] = "1";
		s_arr[8] = "0";
		s_arr[9] = "0";
		s_arr[10] = "0";
		s_arr[11] = "0";
		s_arr[12] = "0";
		s_arr[13] = "0";
		s_arr[14] = "0";
		s_arr[15] = "0";
		s_arr[16] = "030";
		s_arr[17] = "0";
		s_arr[18] = "0";
		
		return s_arr;
	}
	
	public static void PCMA03(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(12);
		
		JSONObject mdr_obj = null;
		JSONObject pymt_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		if(c_outlet.getOutlet().getPaymentOpt().length() > 0){
			pymt_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getPaymentOpt());
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "PCAM03";
		System.out.println("*** " + screen_id + " ***");
		
		// Product ID : Visa_POS
		String in_22 = mdr_obj.get("22").toString();	// VISA MASTER POS - MCC Code
		
		if(in_22 != null && in_22.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("POS", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_POS", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_POS", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_M2U
			String in_28 = mdr_obj.get("28").toString();	// VISA MASTER M2U - MCC Code
			
			if(in_28 != null && in_28.length() > 0){
				s_arr = AutoScript.PCMA03VisaX("M2U", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_M2U", s_arr);
			}
		}
		
		
		// Product ID : Visa_E_Commerce
		String in_27 = mdr_obj.get("27").toString();	// VISA MASTER E-Commerce - MCC Code
		
		if(in_27 != null && in_27.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("EC", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E_Commerce", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E_Commerce", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_RPS
			String in_26 = mdr_obj.get("26").toString();	// VISA MASTER RPS - MCC Code
			
			if(in_26 != null && in_26.length() > 0){
				s_arr = AutoScript.PCMA03VisaX("RPS", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_RPS", s_arr);
			}
		}
		
		
		// Product ID : Visa_MO
		String in_24 = mdr_obj.get("24").toString();	// VISA MASTER MO - MCC Code
		
		if(in_24 != null && in_24.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("MO", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_MO", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_MO", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_TO
			String in_25 = mdr_obj.get("25").toString();	// VISA MASTER TO - MCC Code
			
			if(in_25 != null && in_25.length() > 0){
				s_arr = AutoScript.PCMA03VisaX("TO", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_TO", s_arr);
			}
			
			// Product ID : Visa_ORS
			String in_29 = mdr_obj.get("29").toString();	// VISA MASTER ORS - MCC Code
			
			if(in_29 != null && in_29.length() > 0){
				s_arr = AutoScript.PCMA03VisaX("ORS", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_ORS", s_arr);
			}
			
			
			// Product ID : Visa_DCC
			String in_23 = mdr_obj.get("29").toString();	// VISA MASTER DCC - MCC Code
			
			if(in_23 != null && in_23.length() > 0){
				s_arr = AutoScript.PCMA03VisaX("DCC", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_DCC", s_arr);
			}
		}
				
		
		// Product ID : Visa_E3
		String in_190 = mdr_obj.get("190").toString();	// VISA MASTER E3 - MID No Face To Face

		if(in_190 != null && in_190.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("E3", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E3", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E3", s_arr);
			}
		}
		
		// Product ID : Visa_E6
		String in_191 = mdr_obj.get("191").toString();	// VISA MASTER E6 - MID No Face To Face

		if(in_191 != null && in_191.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("E6", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E6", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E6", s_arr);
			}
		}
		
		// Product ID : Visa_E9
		String in_192 = mdr_obj.get("192").toString();	// VISA MASTER E9 - MID No Face To Face

		if(in_192 != null && in_192.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("E9", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E9", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E9", s_arr);
			}
		}
		
		// Product ID : Visa_E12
		String in_193 = mdr_obj.get("193").toString();	// VISA MASTER E12 - MID No Face To Face

		if(in_193 != null && in_193.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("E12", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E12", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E12", s_arr);
			}
		}
		
		// Product ID : Visa_E18
		String in_194 = mdr_obj.get("194").toString();	// VISA MASTER E18 - MID No Face To Face

		if(in_194 != null && in_194.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("E18", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E18", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E18", s_arr);
			}
		}
		
		// Product ID : Visa_E24
		String in_195 = mdr_obj.get("195").toString();	// VISA MASTER E24 - MID No Face To Face

		if(in_195 != null && in_195.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("E24", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E24", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E24", s_arr);
			}
		}
		
		// Product ID : Visa_E30
		String in_196 = mdr_obj.get("196").toString();	// VISA MASTER E30 - MID No Face To Face

		if(in_196 != null && in_196.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("E30", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E30", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E30", s_arr);
			}
		}
		
		// Product ID : Visa_E36
		String in_197 = mdr_obj.get("197").toString();	// VISA MASTER E36 - MID No Face To Face

		if(in_197 != null && in_197.length() > 0){
			s_arr = AutoScript.PCMA03VisaX("E36", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E36", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E36", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : AMEX_POS
			String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
			
			if(in_283 != null && in_283.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("POS", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_POS", s_arr);
			}
			
			// Product ID : AMEX_MO
			String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
			
			if(in_284 != null && in_284.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("MO", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_MO", s_arr);
			}
			
			// Product ID : AMEX_E_Commerce
			String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
			
			if(in_287 != null && in_287.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("EC", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
			}
			
			// Product ID : AMEX_RPS
			String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
			
			if(in_286 != null && in_286.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("RPS", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_RPS", s_arr);
			}
			
			// Product ID : AMEX_M2U
			String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
			
			if(in_288 != null && in_288.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("M2U", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_M2U", s_arr);
			}
			
			// Product ID : AMEX_L5 / AMEX_L6
			String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
			
			if(in_349 != null && in_349.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("L5", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L5", s_arr);
				
				s_arr = AutoScript.PCMA03AmexX("L6", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L6", s_arr);
			}
			
			
			// Product ID : AMEX_E3
			String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
			
			if(in_435 != null && in_435.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("E3", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E3", s_arr);
			}
			
			// Product ID : AMEX_E6
			String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
			
			if(in_436 != null && in_436.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("E6", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E6", s_arr);
			}
			
			// Product ID : AMEX_E9
			String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
			
			if(in_437 != null && in_437.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("E9", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E9", s_arr);
			}
			
			// Product ID : AMEX_E12
			String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
			
			if(in_438 != null && in_438.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("E12", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E12", s_arr);
			}
			
			// Product ID : AMEX_E18
			String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
			
			if(in_439 != null && in_439.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("E18", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E18", s_arr);
			}
			
			// Product ID : AMEX_E24
			String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
			
			if(in_440 != null && in_440.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("E24", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E24", s_arr);
			}
			
			// Product ID : AMEX_E30
			String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
			
			if(in_441 != null && in_441.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("E30", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E30", s_arr);
			}
			
			// Product ID : AMEX_E36
			String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
			
			if(in_442 != null && in_442.length() > 0){
				s_arr = AutoScript.PCMA03AmexX("E36", c, c_outlet, mdr_obj, pymt_obj);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E36", s_arr);
			} 
		}
	}
	
	public static String[] PCMA03AmexX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject pymt_obj){
		String[] s_arr = AutoScript.init_arr(12);
		String in_agreement_code = "";
		
		if(p_type.equals("POS")){
			in_agreement_code = mdr_obj.get("289").toString();	// AMEX POS - Agreement Code
		} else if(p_type.equals("MO")){
			in_agreement_code = mdr_obj.get("290").toString();	// AMEX MO - Agreement Code
		} else if(p_type.equals("EC")){
			in_agreement_code = mdr_obj.get("293").toString();	// AMEX E-Commerce - Agreement Code
		} else if(p_type.equals("RPS")){
			in_agreement_code = mdr_obj.get("292").toString();	// AMEX RPS - Agreement Code
		} else if(p_type.equals("M2U")){
			in_agreement_code = mdr_obj.get("294").toString();	// AMEX M2U - Agreement Code
		} else if(p_type.equals("L5")){
			in_agreement_code = mdr_obj.get("361").toString();	// AMEX L5/L6 - Agreement Code
		} else if(p_type.equals("L6")){
			in_agreement_code = mdr_obj.get("361").toString();	// AMEX L5/L6 - Agreement Code
		} else if(p_type.equals("E3")){
			in_agreement_code = mdr_obj.get("379").toString();	// AMEX E3 - Agreement Code
		} else if(p_type.equals("E6")){
			in_agreement_code = mdr_obj.get("380").toString();	// AMEX E6 - Agreement Code
		} else if(p_type.equals("E9")){
			in_agreement_code = mdr_obj.get("381").toString();	// AMEX E9 - Agreement Code
		} else if(p_type.equals("E12")){
			in_agreement_code = mdr_obj.get("382").toString();	// AMEX E12 - Agreement Code
		} else if(p_type.equals("E18")){
			in_agreement_code = mdr_obj.get("383").toString();	// AMEX E18 - Agreement Code
		} else if(p_type.equals("E24")){
			in_agreement_code = mdr_obj.get("384").toString();	// AMEX E24 - Agreement Code
		} else if(p_type.equals("E30")){
			in_agreement_code = mdr_obj.get("385").toString();	// AMEX E30 - Agreement Code
		} else if(p_type.equals("E36")){
			in_agreement_code = mdr_obj.get("386").toString();	// AMEX E36 - Agreement Code
		}
		
		
		if(in_agreement_code.equals("MSO01") || in_agreement_code.equals("MSP02")){
			s_arr[0] = "1";
		} else {
			s_arr[0] = "0";
		}
		
		s_arr[1] = "0";
		s_arr[2] = "0";
		s_arr[3] = "0";
		s_arr[4] = "N";
		s_arr[5] = "001";
		s_arr[6] = "S";
		s_arr[7] = "";
		s_arr[8] = "";
		s_arr[9] = "";
		s_arr[10] = "";
		s_arr[11] = "";
		
		return s_arr;
	}
	
	public static String[] PCMA03VisaX(String visa_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject pymt_obj){
		String[] s_arr = AutoScript.init_arr(12);
		
		String visa_1 = "";
		String visa_3 = "";
		String visa_4 = "";
		String visa_5 = "";
		
		if(pymt_obj != null){
			visa_1 = pymt_obj.get("visa_1").toString();
			visa_3 = pymt_obj.get("visa_3").toString();
			visa_4 = pymt_obj.get("visa_4").toString();
			visa_5 = pymt_obj.get("visa_5").toString();
		}
		
		s_arr[0] = "0";
		s_arr[1] = "0";
		s_arr[2] = "00";
		
		if(visa_1.equals("interbank_giro")){
			s_arr[3] = visa_3 + visa_4 + visa_5;
		}
		
		s_arr[4] = "";
		s_arr[5] = "";
		
		if(visa_type.equals("POS")){
			s_arr[6] = "A";
			s_arr[7] = "";
			s_arr[8] = "2";
			s_arr[9] = "90";
			s_arr[10] = "5";
			s_arr[11] = "1";
		} else if(visa_type.equals("M2U")){
			s_arr[6] = "S";
			s_arr[7] = "7";
			s_arr[8] = "";
			s_arr[9] = "01";
			s_arr[10] = "";
			s_arr[11] = "";
		} else if(visa_type.equals("EC")){
			s_arr[6] = "S";
			s_arr[7] = "7";
			s_arr[8] = "";
			s_arr[9] = "01";
			s_arr[10] = "";
			s_arr[11] = "";
		} else if(visa_type.equals("RPS")){
			s_arr[6] = "T";
			s_arr[7] = "2";
			s_arr[8] = "";
			s_arr[9] = "01";
			s_arr[10] = "";
			s_arr[11] = "";
		} else if(visa_type.equals("MO")){
			s_arr[6] = "T";
			s_arr[7] = "1";
			s_arr[8] = "";
			s_arr[9] = "01";
			s_arr[10] = "";
			s_arr[11] = "";
		} else if(visa_type.equals("TO")){
			s_arr[6] = "T";
			s_arr[7] = "1";
			s_arr[8] = "";
			s_arr[9] = "01";
			s_arr[10] = "";
			s_arr[11] = "";
		} else {
			s_arr[6] = "A";
			s_arr[7] = "";
			s_arr[8] = "2";
			s_arr[9] = "90";
			s_arr[10] = "5";
			s_arr[11] = "1";
		}
		
		return s_arr;
	}
	
	public static void PCMA04(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = null;
		
		JSONObject mdr_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		
		//String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "PCAM04";
		System.out.println("*** " + screen_id + " ***");
		
		// Product ID : Visa_POS
		String in_22 = mdr_obj.get("22").toString();	// VISA MASTER POS - MCC Code
		
		if(in_22 != null && in_22.length() > 0){
			s_arr = AutoScript.PCMA04VisaPOS(c, c_outlet, mdr_obj);
			//s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_POS", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_POS", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_M2U
			String in_28 = mdr_obj.get("28").toString();	// VISA MASTER M2U - MCC Code
			
			if(in_28 != null && in_28.length() > 0){
				s_arr = AutoScript.PCMA04VisaX("M2U", c, c_outlet, mdr_obj);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_M2U", s_arr);
			}
		}
		
		
		// Product ID : Visa_E_Commerce
		String in_27 = mdr_obj.get("27").toString();	// VISA MASTER E-Commerce - MCC Code
		
		if(in_27 != null && in_27.length() > 0){
			if(c.getCountryCode().equals("PH")){
				s_arr = AutoScript.PCMA04VisaEC(c, c_outlet, mdr_obj);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "PH_VISA_E_Commerce", s_arr);
			} else {
				s_arr = AutoScript.PCMA04VisaEC(c, c_outlet, mdr_obj);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_E_Commerce", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_RPS
			String in_26 = mdr_obj.get("26").toString();	// VISA MASTER RPS - MCC Code
			
			if(in_26 != null && in_26.length() > 0){
				s_arr = AutoScript.PCMA04VisaX("RPS", c, c_outlet, mdr_obj);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_RPS", s_arr);
			}
		}
		
		
		// Product ID : Visa_MO
		String in_24 = mdr_obj.get("24").toString();	// VISA MASTER MO - MCC Code
		
		if(in_24 != null && in_24.length() > 0){
			if(c.getCountryCode().equals("PH")){
				s_arr = AutoScript.PCMA04VisaX("MO", c, c_outlet, mdr_obj);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "PH_VISA_MO", s_arr);
			} else {
				s_arr = AutoScript.PCMA04VisaX("MO", c, c_outlet, mdr_obj);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_MO", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_TO
			String in_25 = mdr_obj.get("25").toString();	// VISA MASTER TO - MCC Code
			
			if(in_25 != null && in_25.length() > 0){
				s_arr = AutoScript.PCMA04VisaX("TO", c, c_outlet, mdr_obj);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_TO", s_arr);
			}
			
			
			// Product ID : Visa_ORS
			String in_29 = mdr_obj.get("29").toString();	// VISA MASTER ORS - MCC Code
			
			if(in_29 != null && in_29.length() > 0){
				s_arr = AutoScript.PCMA04VisaORS(c, c_outlet, mdr_obj);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_ORS", s_arr);
			}
			
			
			// Product ID : Visa_DCC
			String in_23 = mdr_obj.get("29").toString();	// VISA MASTER DCC - MCC Code
			
			if(in_23 != null && in_23.length() > 0){
				s_arr = AutoScript.PCMA04VisaX("DCC", c, c_outlet, mdr_obj);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "VISA_DCC", s_arr);
			}
		}
				
		
		// Product ID : Visa_E3
		String in_190 = mdr_obj.get("190").toString();	// VISA MASTER E3 - MID No Face To Face

		if(in_190 != null && in_190.length() > 0){
			s_arr = AutoScript.PCMA04VisaEX("E3", c, c_outlet, mdr_obj);
			//s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E3", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E3", s_arr);
			}
		}
		
		// Product ID : Visa_E6
		String in_191 = mdr_obj.get("191").toString();	// VISA MASTER E6 - MID No Face To Face

		if(in_191 != null && in_191.length() > 0){
			s_arr = AutoScript.PCMA04VisaEX("E6", c, c_outlet, mdr_obj);
			//s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E6", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E6", s_arr);
			}
		}
		
		// Product ID : Visa_E9
		String in_192 = mdr_obj.get("192").toString();	// VISA MASTER E9 - MID No Face To Face

		if(in_192 != null && in_192.length() > 0){
			s_arr = AutoScript.PCMA04VisaEX("E9", c, c_outlet, mdr_obj);
			//s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E9", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E9", s_arr);
			}
		}
		
		// Product ID : Visa_E12
		String in_193 = mdr_obj.get("193").toString();	// VISA MASTER E12 - MID No Face To Face

		if(in_193 != null && in_193.length() > 0){
			s_arr = AutoScript.PCMA04VisaEX("E12", c, c_outlet, mdr_obj);
			//s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E12", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E12", s_arr);
			}
		}
		
		// Product ID : Visa_E18
		String in_194 = mdr_obj.get("194").toString();	// VISA MASTER E18 - MID No Face To Face

		if(in_194 != null && in_194.length() > 0){
			s_arr = AutoScript.PCMA04VisaEX("E18", c, c_outlet, mdr_obj);
			//s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E18", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E18", s_arr);
			}
		}
		
		// Product ID : Visa_E24
		String in_195 = mdr_obj.get("195").toString();	// VISA MASTER E24 - MID No Face To Face

		if(in_195 != null && in_195.length() > 0){
			s_arr = AutoScript.PCMA04VisaEX("E24", c, c_outlet, mdr_obj);
			//s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E24", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E24", s_arr);
			}
		}
		
		// Product ID : Visa_E30
		String in_196 = mdr_obj.get("196").toString();	// VISA MASTER E30 - MID No Face To Face

		if(in_196 != null && in_196.length() > 0){
			s_arr = AutoScript.PCMA04VisaEX("E30", c, c_outlet, mdr_obj);
			//s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E30", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E30", s_arr);
			}
		}
		
		// Product ID : Visa_E36
		String in_197 = mdr_obj.get("197").toString();	// VISA MASTER E36 - MID No Face To Face

		if(in_197 != null && in_197.length() > 0){
			s_arr = AutoScript.PCMA04VisaEX("E36", c, c_outlet, mdr_obj);
			//s_arr = AutoScript.concat(s_arr, data_arr);
			
			if(c.getCountryCode().equals("PH")){
				AutoScript.save(screen_id, "PH_VISA_E36", s_arr);
			} else {
				AutoScript.save(screen_id, "VISA_E36", s_arr);
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : AMEX_POS
			String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
			
			if(in_283 != null && in_283.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("POS", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_POS", s_arr);
			}
			
			// Product ID : AMEX_MO
			String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
			
			if(in_284 != null && in_284.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("MO", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_MO", s_arr);
			}
			
			// Product ID : AMEX_E_Commerce
			String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
			
			if(in_287 != null && in_287.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("EC", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
			}
			
			// Product ID : AMEX_RPS
			String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
			
			if(in_286 != null && in_286.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("RPS", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_RPS", s_arr);
			}
			
			// Product ID : AMEX_M2U
			String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
			
			if(in_288 != null && in_288.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("M2U", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_M2U", s_arr);
			}
			
			// Product ID : AMEX_L5 / AMEX_L6
			String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
			
			if(in_349 != null && in_349.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("L5", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L5", s_arr);
				
				s_arr = AutoScript.PCMA04AmexX("L6", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L6", s_arr);
			}
			
			
			// Product ID : AMEX_E3
			String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
			
			if(in_435 != null && in_435.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("E3", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E3", s_arr);
			}
			
			// Product ID : AMEX_E6
			String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
			
			if(in_436 != null && in_436.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("E6", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E6", s_arr);
			}
			
			// Product ID : AMEX_E9
			String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
			
			if(in_437 != null && in_437.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("E9", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E9", s_arr);
			}
			
			// Product ID : AMEX_E12
			String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
			
			if(in_438 != null && in_438.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("E12", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E12", s_arr);
			}
			
			// Product ID : AMEX_E18
			String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
			
			if(in_439 != null && in_439.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("E18", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E18", s_arr);
			}
			
			// Product ID : AMEX_E24
			String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
			
			if(in_440 != null && in_440.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("E24", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E24", s_arr);
			}
			
			// Product ID : AMEX_E30
			String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
			
			if(in_441 != null && in_441.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("E30", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E30", s_arr);
			}
			
			// Product ID : AMEX_E36
			String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
			
			if(in_442 != null && in_442.length() > 0){
				s_arr = AutoScript.PCMA04AmexX("E36", c, c_outlet);
				//s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E36", s_arr);
			} 
		}
	}
	
	public static String[] PCMA04AmexX(String p_type, Casemast c, CaseOutlet c_outlet){
		String[] s_arr = AutoScript.init_arr(1);
		
		s_arr[0] = "1";
		
		return s_arr;
	}
	
	public static String[] PCMA04VisaPOS(Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj){
		int s_len = 13;
		if(c.getCountryCode().equals("PH")){
			s_len = 11;
		}
		
		String[] s_arr = AutoScript.init_arr(s_len);
		
		String in_30 = mdr_obj.get("30").toString();	// VISA MASTER POS - Visa OnUs
		String in_38 = mdr_obj.get("38").toString();	// VISA MASTER POS - Visa OffUs
		String in_46 = mdr_obj.get("46").toString();	// VISA MASTER POS - Mastercard OnUs
		String in_54 = mdr_obj.get("54").toString();	// VISA MASTER POS - Mastercard OffUs
		String in_62 = mdr_obj.get("62").toString();	// VISA MASTER POS - Visa Debit (Local)
		String in_70 = mdr_obj.get("70").toString();	// VISA MASTER POS - Master Debit (Local)
		String in_78 = mdr_obj.get("78").toString();	// VISA MASTER POS - EFTPOS - ATM
		String in_86 = mdr_obj.get("86").toString();	// VISA MASTER POS - MEPS EPOS
		String in_94 = mdr_obj.get("94").toString();	// VISA MASTER POS - Maestro
		String in_102 = mdr_obj.get("102").toString();	// VISA MASTER POS - JCB
		
		if(in_30.length() > 0 || in_38.length() > 0){
			s_arr[0] = "1";
		} else {
			s_arr[0] = "0";
		}
		
		if(in_46.length() > 0 || in_54.length() > 0){
			s_arr[1] = "1";
		} else {
			s_arr[1] = "0";
		}
		
		s_arr[2] = "0";
		s_arr[3] = "0";
		
		
		if(c.getCountryCode().equals("PH")){
			s_arr[4] = "0";
			s_arr[5] = "0";
		}
		else {
			if(in_78.length() > 0){
				s_arr[4] = "1";
			} else {
				s_arr[4] = "0";
			}
			
			if(in_102.length() > 0){
				s_arr[5] = "1";
			} else {
				s_arr[5] = "0";
			}
		}
		
		
		s_arr[6] = "0";
		s_arr[7] = "0";
		s_arr[8] = "0";
		
		if(c.getCountryCode().equals("PH")){
			s_arr[9] = "0";
			s_arr[10] = "0";
		}
		else {
			if(in_94.length() > 0){
				s_arr[9] = "1,maestro,mc,mc,m,00000003,r,00000004 ";
			} else {
				s_arr[9] = "0,,,,,,,";
			}
			
			if(in_86.length() > 0){
				s_arr[10] = "1,meps epos,eft,pl,p,00000005,r,00000006 ";
			} else {
				s_arr[10] = "0,,,,,,,";
			}
		}
		
		
		if(c.getCountryCode().equals("MY")){
			if(in_62.length() > 0){
				//s_arr[11] = "1,VISA DEBIT,visa,vd,V,40000000,r,49999998";
				s_arr[11] = "1,VISA DEBIT,visa,vd,V,40000000,r,49999997";
			} else {
				s_arr[11] = "0,,,,,,,";
			}
			
			if(in_70.length() > 0){
				//s_arr[12] = "1,MASTERCARD DEBIT,mc,md,M,51000000,r,55999998";
				s_arr[12] = "1,MASTERCARD DEBIT,mc,md,M,51000000,r,55999997";
			} else {
				s_arr[12] = "0";
			}
		}
		
		return s_arr;
	}
	
	public static String[] PCMA04VisaEC(Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj){
		int s_len = 10;
		if(c.getCountryCode().equals("PH")){
			s_len = 3;
		}
		
		String[] s_arr = AutoScript.init_arr(s_len);
		
		String in_visa_onus = mdr_obj.get("35").toString();	// VISA MASTER E-Commerce - Visa OnUs
		String in_visa_offus = mdr_obj.get("43").toString();	// VISA MASTER E-Commerce - Visa OffUs
		String in_master_onus = mdr_obj.get("51").toString();	// VISA MASTER E-Commerce - Mastercard OnUs
		String in_master_offus = mdr_obj.get("59").toString();	// VISA MASTER E-Commerce - Mastercard OffUs
		String in_visa_debit = mdr_obj.get("67").toString();	// VISA MASTER E-Commerce - Visa Debit (Local)
		String in_master_debit = mdr_obj.get("75").toString();	// VISA MASTER E-Commerce - Master Debit (Local)
		
		if(in_visa_onus.length() > 0 || in_visa_offus.length() > 0){
			s_arr[0] = "1";
		} else {
			s_arr[0] = "0";
		}
		
		if(in_master_onus.length() > 0 || in_master_offus.length() > 0){
			s_arr[1] = "1";
		} else {
			s_arr[1] = "0";
		}
		
		s_arr[2] = "0";
		
		if(s_len > 3){
			s_arr[3] = "0";
			s_arr[4] = "0";
			s_arr[5] = "0";
			
			//s_arr[6] = "visa ssl,visa,vs,v,40000000,r,49999998";
			//s_arr[7] = "mastercard ssl,mc,ms,m,51000000,r,55999998";
			s_arr[6] = "visa ssl,visa,vs,v,00000005,r,00000006";
			s_arr[7] = "mastercard ssl,mc,ms,m,00000007,r,00000008";
			
			if(in_visa_debit.length() > 0){
				//s_arr[8] = "1,VISA DEBIT,visa,vd,V,40000000,r,49999998";
				s_arr[8] = "1,VISA DEBIT,visa,vd,V,40000000,r,49999997";
			} else {
				s_arr[8] = "0";
			}
			
			if(in_master_debit.length() > 0){
				//s_arr[9] = "1,MASTERCARD DEBIT,mc,md,M,51000000,r,55999998";
				s_arr[9] = "1,MASTERCARD DEBIT,mc,md,M,51000000,r,55999997";
			} else {
				s_arr[9] = "0";
			}
		}
		
		return s_arr;
	}
	
	public static String[] PCMA04VisaORS(Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj){
		String[] s_arr = AutoScript.init_arr(6);
		
		String in_visa_onus = mdr_obj.get("37").toString();	// VISA MASTER ORS - Visa OnUs
		String in_visa_offus = mdr_obj.get("45").toString();	// VISA MASTER ORS - Visa OffUs
		String in_master_onus = mdr_obj.get("53").toString();	// VISA MASTER ORS - Mastercard OnUs
		String in_master_offus = mdr_obj.get("61").toString();	// VISA MASTER ORS - Mastercard OffUs
		String in_kawanku = mdr_obj.get("125").toString();	// VISA MASTER ORS - Kawanku(ORS)
		String in_amex = mdr_obj.get("133").toString();	// VISA MASTER ORS - AMEX(ORS)
		
		if(in_visa_onus.length() > 0 || in_visa_offus.length() > 0){
			s_arr[0] = "1";
		} else {
			s_arr[0] = "0";
		}
		
		if(in_master_onus.length() > 0 || in_master_offus.length() > 0){
			s_arr[1] = "1";
		} else {
			s_arr[1] = "0";
		}
		
		if(in_amex.length() > 0){
			s_arr[2] = "1";
		} else {
			s_arr[2] = "0";
		}
		
		s_arr[3] = "0";
		s_arr[4] = "0";
		
		if(in_kawanku.length() > 0){
			s_arr[5] = "1,KAWANKU1,ATM1,,,P,58873410,r,58873429";
		} else {
			s_arr[5] = "0";
		}
		
		
		return s_arr;
	}
	
	public static String[] PCMA04VisaX(String visa_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj){
		int s_len = 10;
		if(visa_type.equals("DCC") || c.getCountryCode().equals("PH")){
			s_len = 3;
		}
		
		String[] s_arr = AutoScript.init_arr(s_len);
		
		String in_visa_onus = "";
		String in_visa_offus = "";
		String in_master_onus = "";
		String in_master_offus = "";
		String in_visa_debit_local = "";
		String in_master_debit_local = "";
		
		if(visa_type.equals("M2U")){
			in_visa_onus = mdr_obj.get("36").toString();	// VISA MASTER M2U - Visa OnUs
			in_visa_offus = mdr_obj.get("44").toString();	// VISA MASTER M2U - Visa OffUs
			in_master_onus = mdr_obj.get("52").toString();	// VISA MASTER M2U - Mastercard OnUs
			in_master_offus = mdr_obj.get("60").toString();	// VISA MASTER M2U - Mastercard OffUs
			in_visa_debit_local = mdr_obj.get("68").toString();	// VISA MASTER M2U - Visa Debit (Local)
			in_master_debit_local = mdr_obj.get("76").toString();	// VISA MASTER M2U - Master Debit (Local)
		}
		else if(visa_type.equals("RPS")){
			in_visa_onus = mdr_obj.get("34").toString();	// VISA MASTER RPS - Visa OnUs
			in_visa_offus = mdr_obj.get("42").toString();	// VISA MASTER RPS - Visa OffUs
			in_master_onus = mdr_obj.get("50").toString();	// VISA MASTER RPS - Mastercard OnUs
			in_master_offus = mdr_obj.get("58").toString();	// VISA MASTER RPS - Mastercard OffUs
			in_visa_debit_local = mdr_obj.get("66").toString();	// VISA MASTER RPS - Visa Debit (Local)
			in_master_debit_local = mdr_obj.get("74").toString();	// VISA MASTER RPS - Master Debit (Local)
		}
		else if(visa_type.equals("MO")){
			in_visa_onus = mdr_obj.get("32").toString();	// VISA MASTER MO - Visa OnUs
			in_visa_offus = mdr_obj.get("40").toString();	// VISA MASTER MO - Visa OffUs
			in_master_onus = mdr_obj.get("48").toString();	// VISA MASTER MO - Mastercard OnUs
			in_master_offus = mdr_obj.get("56").toString();	// VISA MASTER MO - Mastercard OffUs
			in_visa_debit_local = mdr_obj.get("64").toString();	// VISA MASTER MO - Visa Debit (Local)
			in_master_debit_local = mdr_obj.get("72").toString();	// VISA MASTER MO - Master Debit (Local)
		}
		else if(visa_type.equals("TO")){
			in_visa_onus = mdr_obj.get("33").toString();	// VISA MASTER TO - Visa OnUs
			in_visa_offus = mdr_obj.get("41").toString();	// VISA MASTER TO - Visa OffUs
			in_master_onus = mdr_obj.get("49").toString();	// VISA MASTER TO - Mastercard OnUs
			in_master_offus = mdr_obj.get("57").toString();	// VISA MASTER TO - Mastercard OffUs
			in_visa_debit_local = mdr_obj.get("65").toString();	// VISA MASTER TO - Visa Debit (Local)
			in_master_debit_local = mdr_obj.get("73").toString();	// VISA MASTER TO - Master Debit (Local)
		}
		else if(visa_type.equals("DCC")){
			in_visa_onus = mdr_obj.get("31").toString();	// VISA MASTER DCC - Visa OnUs
			in_visa_offus = mdr_obj.get("39").toString();	// VISA MASTER DCC - Visa OffUs
			in_master_onus = mdr_obj.get("47").toString();	// VISA MASTER DCC - Mastercard OnUs
			in_master_offus = mdr_obj.get("55").toString();	// VISA MASTER DCC - Mastercard OffUs
			in_visa_debit_local = mdr_obj.get("63").toString();	// VISA MASTER DCC - Visa Debit (Local)
			in_master_debit_local = mdr_obj.get("71").toString();	// VISA MASTER DCC - Master Debit (Local)
		}
		
		if(in_visa_onus.length() > 0 || in_visa_offus.length() > 0){
			s_arr[0] = "1";
		} else {
			s_arr[0] = "0";
		}
		
		if(in_master_onus.length() > 0 || in_master_offus.length() > 0){
			s_arr[1] = "1";
		} else {
			s_arr[1] = "0";
		}
		
		s_arr[2] = "0";
		
		if(s_len > 3){
			s_arr[3] = "0";
			s_arr[4] = "0";
			s_arr[5] = "0";
			s_arr[6] = "0";
			s_arr[7] = "0";
			
			if(in_visa_debit_local.length() > 0){
				//s_arr[8] = "1,VISA DEBIT,visa,vd,V,40000000,r,49999998";
				s_arr[8] = "1,VISA DEBIT,visa,vd,V,40000000,r,49999997";
			} else {
				s_arr[8] = "0";
			}
			
			if(in_master_debit_local.length() > 0){
				//s_arr[9] = "1,MASTERCARD DEBIT,mc,md,M,51000000,r,55999998";
				s_arr[9] = "1,MASTERCARD DEBIT,mc,md,M,51000000,r,55999997";
			} else {
				s_arr[9] = "0";
			}
		}
		
		return s_arr;
	}
	
	
	public static String[] PCMA04VisaEX(String visa_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj){
		String[] s_arr = AutoScript.init_arr(3);
		
		String in_ezypay_mdr = "";
		
		if(visa_type.equals("E3")){
			in_ezypay_mdr = mdr_obj.get("246").toString();	// VISA MASTER E3 - MDR
		} else if(visa_type.equals("E6")){
			in_ezypay_mdr = mdr_obj.get("247").toString();	// VISA MASTER E6 - MDR
		} else if(visa_type.equals("E9")){
			in_ezypay_mdr = mdr_obj.get("248").toString();	// VISA MASTER E9 - MDR
		} else if(visa_type.equals("E12")){
			in_ezypay_mdr = mdr_obj.get("249").toString();	// VISA MASTER E12 - MDR
		} else if(visa_type.equals("E18")){
			in_ezypay_mdr = mdr_obj.get("250").toString();	// VISA MASTER E18 - MDR
		} else if(visa_type.equals("E24")){
			in_ezypay_mdr = mdr_obj.get("251").toString();	// VISA MASTER E24 - MDR
		} else if(visa_type.equals("E30")){
			in_ezypay_mdr = mdr_obj.get("252").toString();	// VISA MASTER E30 - MDR
		} else if(visa_type.equals("E36")){
			in_ezypay_mdr = mdr_obj.get("253").toString();	// VISA MASTER E36 - MDR
		}
		
		if(in_ezypay_mdr.length() > 0){
			s_arr[0] = "1";
			s_arr[1] = "1";
		} else {
			s_arr[0] = "0";
			s_arr[1] = "0";
		}
		
		s_arr[2] = "0";
		
		return s_arr;
	}
	
	
	public static void PCMA05(Casemast c, CaseOutlet c_outlet) throws Exception{
		JSONObject mdr_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "PCAM05";
		System.out.println("*** " + screen_id + " ***");
		
		TreeMap<String, String[]> arr = null;
		String[] s_arr = null;
		
		// Product ID : Visa_POS
		String in_22 = mdr_obj.get("22").toString();	// VISA MASTER POS - MCC Code
		
		if(in_22 != null && in_22.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("POS", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_M2U
			String in_28 = mdr_obj.get("28").toString();	// VISA MASTER M2U - MCC Code
			
			if(in_28 != null && in_28.length() > 0){
				arr = AutoScript.PCMA05VisaBatchX("M2U", c, c_outlet, mdr_obj, data_arr);
				AutoScript.save(screen_id, arr);
			}
		}
		
		
		// Product ID : Visa_E_Commerce
		String in_27 = mdr_obj.get("27").toString();	// VISA MASTER E-Commerce - MCC Code
		
		if(in_27 != null && in_27.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("EC", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_RPS
			String in_26 = mdr_obj.get("26").toString();	// VISA MASTER RPS - MCC Code
			
			if(in_26 != null && in_26.length() > 0){
				arr = AutoScript.PCMA05VisaBatchX("RPS", c, c_outlet, mdr_obj, data_arr);
				AutoScript.save(screen_id, arr);
			}
		}
		
		
		// Product ID : Visa_MO
		String in_24 = mdr_obj.get("24").toString();	// VISA MASTER MO - MCC Code
		
		if(in_24 != null && in_24.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("MO", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : Visa_TO
			String in_25 = mdr_obj.get("25").toString();	// VISA MASTER TO - MCC Code
			
			if(in_25 != null && in_25.length() > 0){
				arr = AutoScript.PCMA05VisaBatchX("TO", c, c_outlet, mdr_obj, data_arr);
				AutoScript.save(screen_id, arr);
			}
			
			
			// Product ID : Visa_ORS
			String in_29 = mdr_obj.get("29").toString();	// VISA MASTER ORS - MCC Code
			
			if(in_29 != null && in_29.length() > 0){
				arr = AutoScript.PCMA05VisaBatchX("ORS", c, c_outlet, mdr_obj, data_arr);
				AutoScript.save(screen_id, arr);
			}
			
			
			// Product ID : Visa_DCC
			String in_23 = mdr_obj.get("29").toString();	// VISA MASTER DCC - MCC Code
			
			if(in_23 != null && in_23.length() > 0){
				arr = AutoScript.PCMA05VisaBatchX("DCC", c, c_outlet, mdr_obj, data_arr);
				AutoScript.save(screen_id, arr);
			}
		}
				
		
		// Product ID : Visa_E3
		String in_190 = mdr_obj.get("190").toString();	// VISA MASTER E3 - MID No Face To Face

		if(in_190 != null && in_190.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("E3", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		// Product ID : Visa_E6
		String in_191 = mdr_obj.get("191").toString();	// VISA MASTER E6 - MID No Face To Face

		if(in_191 != null && in_191.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("E6", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		// Product ID : Visa_E9
		String in_192 = mdr_obj.get("192").toString();	// VISA MASTER E9 - MID No Face To Face

		if(in_192 != null && in_192.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("E9", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		// Product ID : Visa_E12
		String in_193 = mdr_obj.get("193").toString();	// VISA MASTER E12 - MID No Face To Face

		if(in_193 != null && in_193.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("E12", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		// Product ID : Visa_E18
		String in_194 = mdr_obj.get("194").toString();	// VISA MASTER E18 - MID No Face To Face

		if(in_194 != null && in_194.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("E18", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		// Product ID : Visa_E24
		String in_195 = mdr_obj.get("195").toString();	// VISA MASTER E24 - MID No Face To Face

		if(in_195 != null && in_195.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("E24", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		// Product ID : Visa_E30
		String in_196 = mdr_obj.get("196").toString();	// VISA MASTER E30 - MID No Face To Face

		if(in_196 != null && in_196.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("E30", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		// Product ID : Visa_E36
		String in_197 = mdr_obj.get("197").toString();	// VISA MASTER E36 - MID No Face To Face

		if(in_197 != null && in_197.length() > 0){
			arr = AutoScript.PCMA05VisaBatchX("E36", c, c_outlet, mdr_obj, data_arr);
			AutoScript.save(screen_id, arr);
		}
		
		
		if(c.getCountryCode().equals("MY")){
			// Product ID : AMEX_POS
			String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
			
			if(in_283 != null && in_283.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("POS", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_POS", s_arr);
			}
			
			// Product ID : AMEX_MO
			String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
			
			if(in_284 != null && in_284.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("MO", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_MO", s_arr);
			}
			
			// Product ID : AMEX_E_Commerce
			String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
			
			if(in_287 != null && in_287.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("EC", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
			}
			
			// Product ID : AMEX_RPS
			String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
			
			if(in_286 != null && in_286.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("RPS", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_RPS", s_arr);
			}
			
			// Product ID : AMEX_M2U
			String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
			
			if(in_288 != null && in_288.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("M2U", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_M2U", s_arr);
			}
			
			// Product ID : AMEX_L5 / AMEX_L6
			String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
			
			if(in_349 != null && in_349.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("L5", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L5", s_arr);
				
				s_arr = AutoScript.PCMA05AmexX("L6", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_L6", s_arr);
			}
			
			
			// Product ID : AMEX_E3
			String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
			
			if(in_435 != null && in_435.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("E3", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E3", s_arr);
			}
			
			// Product ID : AMEX_E6
			String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
			
			if(in_436 != null && in_436.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("E6", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E6", s_arr);
			}
			
			// Product ID : AMEX_E9
			String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
			
			if(in_437 != null && in_437.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("E9", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E9", s_arr);
			}
			
			// Product ID : AMEX_E12
			String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
			
			if(in_438 != null && in_438.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("E12", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E12", s_arr);
			}
			
			// Product ID : AMEX_E18
			String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
			
			if(in_439 != null && in_439.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("E18", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E18", s_arr);
			}
			
			// Product ID : AMEX_E24
			String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
			
			if(in_440 != null && in_440.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("E24", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E24", s_arr);
			}
			
			// Product ID : AMEX_E30
			String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
			
			if(in_441 != null && in_441.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("E30", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E30", s_arr);
			}
			
			// Product ID : AMEX_E36
			String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
			
			if(in_442 != null && in_442.length() > 0){
				s_arr = AutoScript.PCMA05AmexX("E36", c, c_outlet);
				s_arr = AutoScript.concat(s_arr, data_arr);
				
				AutoScript.save(screen_id, "AMEX_E36", s_arr);
			}
		}
	}
	
	public static TreeMap<String, String[]> PCMA05VisaBatchX(String visa_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, String[] data_arr) throws Exception{
		TreeMap<String, String[]> arr = new TreeMap<String, String[]>();
		String[] s_arr = null;
		
		String in_pos_visaonus = mdr_obj.get("30").toString();	// VISA MASTER POS - Visa OnUs
		String in_pos_visaoffus = mdr_obj.get("38").toString();	// VISA MASTER POS - Visa OffUs
		String in_pos_masteronus = mdr_obj.get("46").toString();	// VISA MASTER POS - Mastercard OnUs
		String in_pos_masteroffus = mdr_obj.get("54").toString();	// VISA MASTER POS - Mastercard OffUs
		String in_pos_visadebit = mdr_obj.get("62").toString();	// VISA MASTER POS - Visa Debit (Local)
		String in_pos_masterdebit = mdr_obj.get("70").toString();	// VISA MASTER POS - Master Debit (Local)
		
		String prefix = "";
		if(c.getCountryCode().equals("PH")){
			prefix = c.getCountryCode() + "_";
		}
		
		String prod_visa = "";
		String prod_master = "";
		String prod_visadebit = "";
		String prod_masterdebit = "";
		String in_visaonus = "";
		String in_visaoffus = "";
		String in_masteronus = "";
		String in_masteroffus = "";
		String in_visadebit = "";
		String in_masterdebit = "";
		
		if(visa_type.equals("POS")){
			prod_visa = prefix + "VISA_POS:VISA";
			prod_master = prefix + "VISA_POS:MASTER";
			
			if(c.getCountryCode().equals("MY")){
				prod_visadebit = "VISA_POS:VISA-DEBIT";
				prod_masterdebit = "VISA_POS:MASTER-DEBIT";
			}
			
			in_visaonus = mdr_obj.get("30").toString();		// VISA MASTER POS - Visa OnUs
			in_visaoffus = mdr_obj.get("38").toString();	// VISA MASTER POS - Visa OffUs
			in_masteronus = mdr_obj.get("46").toString();	// VISA MASTER POS - Mastercard OnUs
			in_masteroffus = mdr_obj.get("54").toString();	// VISA MASTER POS - Mastercard OffUs
			in_visadebit = mdr_obj.get("62").toString();	// VISA MASTER POS - Visa Debit (Local)
			in_masterdebit = mdr_obj.get("70").toString();	// VISA MASTER POS - Master Debit (Local)
		
		} else if(visa_type.equals("EC")) {
			prod_visa = prefix + "VISA_E_Commerce:VISA";
			prod_master = prefix + "VISA_E_Commerce:MASTER";
			
			if(c.getCountryCode().equals("MY")){
				prod_visadebit = "VISA_E_Commerce:VISA-DEBIT";
				prod_masterdebit = "VISA_E_Commerce:MASTER-DEBIT";
			}
			
			in_visaonus = mdr_obj.get("35").toString();		// VISA MASTER EC - Visa OnUs
			in_visaoffus = mdr_obj.get("43").toString();	// VISA MASTER EC - Visa OffUs
			in_masteronus = mdr_obj.get("51").toString();	// VISA MASTER EC - Mastercard OnUs
			in_masteroffus= mdr_obj.get("59").toString();	// VISA MASTER EC - Mastercard OffUs
			in_visadebit = mdr_obj.get("67").toString();	// VISA MASTER EC - Visa Debit (Local)
			in_masterdebit = mdr_obj.get("75").toString();	// VISA MASTER EC - Master Debit (Local)
			
		} else if(visa_type.equals("M2U")){
			prod_visa = "VISA_M2U:VISA";
			prod_master = "VISA_M2U:MASTER";
			prod_visadebit = "VISA_M2U:VISA-DEBIT";
			prod_masterdebit = "VISA_M2U:MASTER-DEBIT";
			
			in_visaonus = mdr_obj.get("36").toString();		// VISA MASTER M2U - Visa OnUs
			in_visaoffus = mdr_obj.get("44").toString();	// VISA MASTER M2U - Visa OffUs
			in_masteronus = mdr_obj.get("52").toString();	// VISA MASTER M2U - Mastercard OnUs
			in_masteroffus = mdr_obj.get("60").toString();	// VISA MASTER M2U - Mastercard OffUs
			in_visadebit = mdr_obj.get("68").toString();	// VISA MASTER M2U - Visa Debit (Local)
			in_masterdebit = mdr_obj.get("76").toString();	// VISA MASTER M2U - Master Debit (Local)
		
		} else if(visa_type.equals("RPS")){
			prod_visa = "VISA_RPS:VISA";
			prod_master = "VISA_RPS:MASTER";
			prod_visadebit = "VISA_RPS:VISA-DEBIT";
			prod_masterdebit = "VISA_RPS:MASTER-DEBIT";
			
			in_visaonus = mdr_obj.get("34").toString();		// VISA MASTER RPS - Visa OnUs
			in_visaoffus = mdr_obj.get("42").toString();	// VISA MASTER RPS - Visa OffUs
			in_masteronus = mdr_obj.get("50").toString();	// VISA MASTER RPS - Mastercard OnUs
			in_masteroffus = mdr_obj.get("58").toString();	// VISA MASTER RPS - Mastercard OffUs
			in_visadebit = mdr_obj.get("66").toString();	// VISA MASTER RPS - Visa Debit (Local)
			in_masterdebit = mdr_obj.get("74").toString();	// VISA MASTER RPS - Master Debit (Local)
			
		} else if(visa_type.equals("MO")){
			prod_visa = prefix + "VISA_MO:VISA";
			prod_master = prefix + "VISA_MO:MASTER";
			
			if(c.getCountryCode().equals("MY")){
				prod_visadebit = "VISA_MO:VISA-DEBIT";
				prod_masterdebit = "VISA_MO:MASTER-DEBIT";
			}
			
			in_visaonus = mdr_obj.get("32").toString();		// VISA MASTER MO - Visa OnUs
			in_visaoffus = mdr_obj.get("40").toString();	// VISA MASTER MO - Visa OffUs
			in_masteronus = mdr_obj.get("48").toString();	// VISA MASTER MO - Mastercard OnUs
			in_masteroffus = mdr_obj.get("56").toString();	// VISA MASTER MO - Mastercard OffUs
			in_visadebit = mdr_obj.get("64").toString();	// VISA MASTER MO - Visa Debit (Local)
			in_masterdebit = mdr_obj.get("72").toString();	// VISA MASTER MO - Master Debit (Local)
			
		} else if(visa_type.equals("TO")){
			prod_visa = "VISA_TO:VISA";
			prod_master = "VISA_TO:MASTER";
			prod_visadebit = "VISA_TO:VISA-DEBIT";
			prod_masterdebit = "VISA_TO:MASTER-DEBIT";
			
			in_visaonus = mdr_obj.get("33").toString();		// VISA MASTER TO - Visa OnUs
			in_visaoffus = mdr_obj.get("41").toString();	// VISA MASTER TO - Visa OffUs
			in_masteronus = mdr_obj.get("49").toString();	// VISA MASTER TO - Mastercard OnUs
			in_masteroffus = mdr_obj.get("57").toString();	// VISA MASTER TO - Mastercard OffUs
			in_visadebit = mdr_obj.get("65").toString();	// VISA MASTER TO - Visa Debit (Local)
			in_masterdebit = mdr_obj.get("73").toString();	// VISA MASTER TO - Master Debit (Local)
			
		} else if(visa_type.equals("ORS")){
			prod_visa = "VISA_ORS:VISA";
			prod_master = "VISA_ORS:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = mdr_obj.get("37").toString();	// VISA MASTER ORS - Visa OnUs
			in_visaoffus = "0.000";
			in_masteronus = mdr_obj.get("53").toString();	// VISA MASTER ORS - Mastercard OnUs
			in_masteroffus = "0.000";
			in_visadebit = "";
			in_masterdebit = "";
			
		} else if(visa_type.equals("DCC")){
			prod_visa = "VISA_DCC:VISA";
			prod_master = "VISA_DCC:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = "0.000";
			in_visaoffus = mdr_obj.get("39").toString();	// VISA MASTER DCC - Visa OffUs
			in_masteronus = "0.000";
			in_masteroffus = mdr_obj.get("55").toString();	// VISA MASTER DCC - Mastercard OffUs
			
		} else if(visa_type.equals("E3")){
			prod_visa = prefix + "VISA_E3:VISA";
			prod_master = prefix + "VISA_E3:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = "0.000";
			in_visaoffus = mdr_obj.get("246").toString();	// VISA MASTER E3 - Visa/Master %
			in_masteronus = "0.000";
			in_masteroffus = mdr_obj.get("246").toString();	// VISA MASTER E3 - Visa/Master %
		
		} else if(visa_type.equals("E6")){
			prod_visa = prefix + "VISA_E6:VISA";
			prod_master = prefix + "VISA_E6:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = "0.000";
			in_visaoffus = mdr_obj.get("247").toString();	// VISA MASTER E6 - Visa/Master %
			in_masteronus = "0.000";
			in_masteroffus = mdr_obj.get("247").toString();	// VISA MASTER E6 - Visa/Master %
		
		} else if(visa_type.equals("E9")){
			prod_visa = prefix + "VISA_E9:VISA";
			prod_master = prefix + "VISA_E9:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = "0.000";
			in_visaoffus = mdr_obj.get("248").toString();	// VISA MASTER E9 - Visa/Master %
			in_masteronus = "0.000";
			in_masteroffus = mdr_obj.get("248").toString();	// VISA MASTER E9 - Visa/Master %
		
		} else if(visa_type.equals("E12")){
			prod_visa = prefix + "VISA_E12:VISA";
			prod_master = prefix + "VISA_E12:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = "0.000";
			in_visaoffus = mdr_obj.get("249").toString();	// VISA MASTER E12 - Visa/Master %
			in_masteronus = "0.000";
			in_masteroffus = mdr_obj.get("249").toString();	// VISA MASTER E12 - Visa/Master %
		
		} else if(visa_type.equals("E18")){
			prod_visa = prefix + "VISA_E18:VISA";
			prod_master = prefix + "VISA_E18:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = "0.000";
			in_visaoffus = mdr_obj.get("250").toString();	// VISA MASTER E18 - Visa/Master %
			in_masteronus = "0.000";
			in_masteroffus = mdr_obj.get("250").toString();	// VISA MASTER E18 - Visa/Master %
		
		} else if(visa_type.equals("E24")){
			prod_visa = prefix + "VISA_E24:VISA";
			prod_master = prefix + "VISA_E24:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = "0.000";
			in_visaoffus = mdr_obj.get("251").toString();	// VISA MASTER E24 - Visa/Master %
			in_masteronus = "0.000";
			in_masteroffus = mdr_obj.get("251").toString();	// VISA MASTER E24 - Visa/Master %
		
		} else if(visa_type.equals("E30")){
			prod_visa = prefix + "VISA_E30:VISA";
			prod_master = prefix + "VISA_E30:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = "0.000";
			in_visaoffus = mdr_obj.get("252").toString();	// VISA MASTER E30 - Visa/Master %
			in_masteronus = "0.000";
			in_masteroffus = mdr_obj.get("252").toString();	// VISA MASTER E30 - Visa/Master %
		
		} else if(visa_type.equals("E36")){
			prod_visa = prefix + "VISA_E36:VISA";
			prod_master = prefix + "VISA_E36:MASTER";
			prod_visadebit = "";
			prod_masterdebit = "";
			
			in_visaonus = "0.000";
			in_visaoffus = mdr_obj.get("253").toString();	// VISA MASTER E36 - Visa/Master %
			in_masteronus = "0.000";
			in_masteroffus = mdr_obj.get("253").toString();	// VISA MASTER E36 - Visa/Master %
		
		}
		
		
		
		if(prod_visa.length() > 0 && (in_pos_visaonus.length() > 0 || in_pos_visaoffus.length() > 0)){
			s_arr = AutoScript.PCMA05VisaX(prod_visa, in_visaoffus, in_visaonus);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			arr.put(prod_visa, s_arr);
		}
		
		if(prod_master.length() > 0 && (in_pos_masteronus.length() > 0 || in_pos_masteroffus.length() > 0)){
			s_arr = AutoScript.PCMA05VisaX(prod_master, in_masteroffus, in_masteronus);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			arr.put(prod_master, s_arr);
		}
		
		
		
		if(c.getCountryCode().equals("MY")){
			if(visa_type.equals("EC")){
				if(in_pos_visaonus.length() > 0 || in_pos_visaoffus.length() > 0){
					s_arr = AutoScript.PCMA05VisaX("E_Commerce_VISA-SSL", in_visaoffus, in_visaonus);
					s_arr = AutoScript.concat(s_arr, data_arr);
					
					arr.put("VISA_E_Commerce:VISA-SSL", s_arr);
				}
				
				
				if(in_pos_masteronus.length() > 0 || in_pos_masteroffus.length() > 0){
					s_arr = AutoScript.PCMA05VisaX("E_Commerce_MASTER-SSL", in_masteroffus, in_masteronus);
					s_arr = AutoScript.concat(s_arr, data_arr);
					
					arr.put("VISA_E_Commerce:MASTER-SSL", s_arr);
				}
			}
			
			
			if(visa_type.equals("POS")){
				String in_78 = mdr_obj.get("78").toString();	// VISA MASTER POS - EFTPOS - ATM
				String in_86 = mdr_obj.get("86").toString();	// VISA MASTER POS - MEPS EPOS
				String in_94 = mdr_obj.get("94").toString();	// VISA MASTER POS - Maestro
				String in_102 = mdr_obj.get("102").toString();	// VISA MASTER POS - JCB
				
				
				if(in_78.length() > 0){
					s_arr = AutoScript.PCMA05VisaX("POS_EFTPOS-ATM", in_78, "0.000");
					s_arr = AutoScript.concat(s_arr, data_arr);
					
					arr.put("VISA_POS:EFTPOS-ATM", s_arr);
				}
				
				if(in_102.length() > 0){
					s_arr = AutoScript.PCMA05VisaX("POS_JCB", in_102, "0.000");
					s_arr = AutoScript.concat(s_arr, data_arr);
					
					arr.put("VISA_POS:JCB", s_arr);
				}
				
				if(in_94.length() > 0){
					s_arr = AutoScript.PCMA05VisaX("POS_Maestro", in_94, "0.000");
					s_arr = AutoScript.concat(s_arr, data_arr);
					
					arr.put("VISA_POS:Maestro", s_arr);
				}
				
				if(in_86.length() > 0){
					s_arr = AutoScript.PCMA05VisaX("POS_MEPS-EPOS", in_86, "0.000");
					s_arr = AutoScript.concat(s_arr, data_arr);
					
					arr.put("VISA_POS:MEPS-EPOS", s_arr);
				}
			}
			
		
			if(visa_type.equals("ORS")){
				String in_133 = mdr_obj.get("133").toString();	// VISA MASTER ORS - Amex (ORS)
				String in_125 = mdr_obj.get("125").toString();	// VISA MASTER ORS - KawanKu1 (ORS)
				
				if(in_133.length() > 0){
					s_arr = AutoScript.PCMA05VisaX("ORS_AMEX", "0.000", in_133);
					s_arr = AutoScript.concat(s_arr, data_arr);
					
					arr.put("VISA_ORS:AMEX", s_arr);
				}
				
				if(in_125.length() > 0){
					s_arr = AutoScript.PCMA05VisaX("ORS_KAWANKU1", "0.000", in_125);
					s_arr = AutoScript.concat(s_arr, data_arr);
					
					arr.put("VISA_ORS:KAWANKU1", s_arr);
				}
			}
		}
		
		
		if(prod_visadebit.length() > 0 && in_pos_visadebit.length() > 0){
			s_arr = AutoScript.PCMA05VisaX(prod_visadebit, in_visadebit, "0.000");
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			arr.put(prod_visadebit, s_arr);
		}
		
		if(prod_masterdebit.length() > 0 && in_pos_masterdebit.length() > 0){
			s_arr = AutoScript.PCMA05VisaX(prod_masterdebit, in_masterdebit, "0.000");
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			arr.put(prod_masterdebit, s_arr);
		}
		
		
		return arr;
	}
	
	public static String[] PCMA05VisaX(String visa_type, String in_1, String in_2){
		String[] s_arr = AutoScript.init_arr(9);
		
		s_arr[0] = "0000000";
		s_arr[1] = "000";
		s_arr[2] = "0";
		s_arr[3] = "2";
		s_arr[4] = AutoScript.format_decimal(in_1, 5);
		s_arr[5] = "00000";
		s_arr[6] = "0000000";
		s_arr[7] = AutoScript.format_decimal(in_2, 5);
		s_arr[8] = "0000000";
		
		return s_arr;
	}
	
	public static String[] PCMA05AmexX(String p_type, Casemast c, CaseOutlet c_outlet){
		String[] s_arr = AutoScript.init_arr(9);
		
		s_arr[0] = "0000000";
		s_arr[1] = "000";
		s_arr[2] = "0000";
		s_arr[3] = "2";
		s_arr[4] = "";
		s_arr[5] = "00000";
		s_arr[6] = "0000000";
		s_arr[7] = "00000";
		s_arr[8] = "0000000";
		
		return s_arr;
	}
	
	public static void AMAM01(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(8);
		JSONObject mdr_obj = null;
		JSONObject pymt_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		if(c_outlet.getOutlet().getPaymentOpt().length() > 0){
			pymt_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getPaymentOpt());
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "AMAM01";
		System.out.println("*** " + screen_id + " ***");
		
		
		// Product ID : AMEX_POS
		String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		
		if(in_283 != null && in_283.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("POS", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_POS", s_arr);
		}
		
		// Product ID : AMEX_MO
		String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
		
		if(in_284 != null && in_284.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("MO", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_MO", s_arr);
		}
		
		// Product ID : AMEX_E_Commerce
		String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
		
		if(in_287 != null && in_287.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("EC", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
		}
		
		// Product ID : AMEX_RPS
		String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
		
		if(in_286 != null && in_286.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("RPS", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_RPS", s_arr);
		}
		
		// Product ID : AMEX_M2U
		String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
		
		if(in_288 != null && in_288.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("M2U", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_M2U", s_arr);
		}
		
		// Product ID : AMEX_L5 / AMEX_L6
		String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		
		if(in_349 != null && in_349.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("L5", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L5", s_arr);
			
			s_arr = AutoScript.AMAM01AmexX("L6", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L6", s_arr);
		}
		
		
		// Product ID : AMEX_E3
		String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
		
		if(in_435 != null && in_435.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("E3", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E3", s_arr);
		}
		
		// Product ID : AMEX_E6
		String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
		
		if(in_436 != null && in_436.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("E6", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E6", s_arr);
		}
		
		// Product ID : AMEX_E9
		String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
		
		if(in_437 != null && in_437.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("E9", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E9", s_arr);
		}
		
		// Product ID : AMEX_E12
		String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
		
		if(in_438 != null && in_438.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("E12", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E12", s_arr);
		}
		
		// Product ID : AMEX_E18
		String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
		
		if(in_439 != null && in_439.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("E18", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E18", s_arr);
		}
		
		// Product ID : AMEX_E24
		String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
		
		if(in_440 != null && in_440.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("E24", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E24", s_arr);
		}
		
		// Product ID : AMEX_E30
		String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
		
		if(in_441 != null && in_441.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("E30", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E30", s_arr);
		}
		
		// Product ID : AMEX_E36
		String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
		
		if(in_442 != null && in_442.length() > 0){
			s_arr = AutoScript.AMAM01AmexX("E36", c, c_outlet, mdr_obj, pymt_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E36", s_arr);
		} 
	}
	
	public static String[] AMAM01AmexX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject pymt_obj){
		String[] s_arr = AutoScript.init_arr(8);
		
		String amex_1 = "";
		String amex_3 = "";
		
		if(pymt_obj != null){
			amex_1 = pymt_obj.get("amex_1").toString();
			amex_3 = pymt_obj.get("amex_3").toString();
		}
		
		
		String in_mid = "";
		
		if(p_type.equals("POS")){
			in_mid = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		} else if(p_type.equals("MO")){
			in_mid = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		} else if(p_type.equals("EC")){
			in_mid = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		} else if(p_type.equals("RPS")){
			in_mid = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		} else if(p_type.equals("M2U")){
			in_mid = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		} else if(p_type.equals("L5")){
			in_mid = mdr_obj.get("337").toString();	// AMEX L5/L6 - MID No L5 Ezypay#
		} else if(p_type.equals("L6")){
			in_mid = mdr_obj.get("343").toString();	// AMEX L5/L6 - MID No L6 Ezypay#
		} else if(p_type.equals("E3")){
			in_mid = mdr_obj.get("411").toString();	// AMEX E3 - MID No Face To Face
		} else if(p_type.equals("E6")){
			in_mid = mdr_obj.get("412").toString();	// AMEX E6 - MID No Face To Face
		} else if(p_type.equals("E9")){
			in_mid = mdr_obj.get("413").toString();	// AMEX E9 - MID No Face To Face
		} else if(p_type.equals("E12")){
			in_mid = mdr_obj.get("414").toString();	// AMEX E12 - MID No Face To Face
		} else if(p_type.equals("E18")){
			in_mid = mdr_obj.get("415").toString();	// AMEX E18 - MID No Face To Face
		} else if(p_type.equals("E24")){
			in_mid = mdr_obj.get("416").toString();	// AMEX E24 - MID No Face To Face
		} else if(p_type.equals("E30")){
			in_mid = mdr_obj.get("417").toString();	// AMEX E30 - MID No Face To Face
		} else if(p_type.equals("E36")){
			in_mid = mdr_obj.get("418").toString();	// AMEX E36 - MID No Face To Face
		}
		
		
		if(amex_1.equals("credit_maybank")){
			s_arr[0] = "000000000000000000";
		}
		else if(amex_1.equals("interbank_giro")){
			s_arr[0] = amex_3;
		}
		else {
			s_arr[0] = "";
		}
		
		
		if(amex_1.equals("banker_cheque")){
			s_arr[1] = "100";
			s_arr[2] = "110";
		} else {
			s_arr[1] = "103";
			s_arr[2] = "112";
		}
		
		s_arr[3] = "31";
		s_arr[4] = " ";
		s_arr[5] = "Y";
		s_arr[6] = in_mid;
		s_arr[7] = c_outlet.getOutlet().getCTEmail();
		
		return s_arr;
	}
	
	
	public static void AMAM02(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(5);
		
		JSONObject mdr_obj = null;
		JSONObject otherinfo_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		if(c_outlet.getOutlet().getOtherInfo().length() > 0){
			otherinfo_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getOtherInfo());
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "AMAM02";
		System.out.println("*** " + screen_id + " ***");
		
		
		// Product ID : AMEX_POS
		String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		
		if(in_283 != null && in_283.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("POS", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_POS", s_arr);
		}
		
		// Product ID : AMEX_MO
		String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
		
		if(in_284 != null && in_284.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("MO", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_MO", s_arr);
		}
		
		// Product ID : AMEX_E_Commerce
		String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
		
		if(in_287 != null && in_287.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("EC", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
		}
		
		// Product ID : AMEX_RPS
		String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
		
		if(in_286 != null && in_286.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("RPS", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_RPS", s_arr);
		}
		
		// Product ID : AMEX_M2U
		String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
		
		if(in_288 != null && in_288.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("M2U", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_M2U", s_arr);
		}
		
		// Product ID : AMEX_L5 / AMEX_L6
		String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		
		if(in_349 != null && in_349.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("L5", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L5", s_arr);
			
			s_arr = AutoScript.AMAM02AmexX("L6", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L6", s_arr);
		}
		
		
		// Product ID : AMEX_E3
		String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
		
		if(in_435 != null && in_435.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("E3", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E3", s_arr);
		}
		
		// Product ID : AMEX_E6
		String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
		
		if(in_436 != null && in_436.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("E6", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E6", s_arr);
		}
		
		// Product ID : AMEX_E9
		String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
		
		if(in_437 != null && in_437.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("E9", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E9", s_arr);
		}
		
		// Product ID : AMEX_E12
		String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
		
		if(in_438 != null && in_438.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("E12", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E12", s_arr);
		}
		
		// Product ID : AMEX_E18
		String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
		
		if(in_439 != null && in_439.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("E18", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E18", s_arr);
		}
		
		// Product ID : AMEX_E24
		String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
		
		if(in_440 != null && in_440.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("E24", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E24", s_arr);
		}
		
		// Product ID : AMEX_E30
		String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
		
		if(in_441 != null && in_441.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("E30", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E30", s_arr);
		}
		
		// Product ID : AMEX_E36
		String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
		
		if(in_442 != null && in_442.length() > 0){
			s_arr = AutoScript.AMAM02AmexX("E36", c, c_outlet, mdr_obj, otherinfo_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E36", s_arr);
		} 
	}
	
	public static String[] AMAM02AmexX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject otherinfo_obj){
		String[] s_arr = AutoScript.init_arr(5);
		
		String in_signing_reason = "";
		String in_old_merchant_no = "";
		
		if(p_type.equals("POS")){
			in_signing_reason = mdr_obj.get("319").toString();	// AMEX POS - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("MO")){
			in_signing_reason = mdr_obj.get("320").toString();	// AMEX MO - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("EC")){
			in_signing_reason = mdr_obj.get("323").toString();	// AMEX E-Commerce - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("RPS")){
			in_signing_reason = mdr_obj.get("322").toString();	// AMEX RPS - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("M2U")){
			in_signing_reason = mdr_obj.get("324").toString();	// AMEX M2U - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("L5")){
			in_signing_reason = mdr_obj.get("373").toString();	// AMEX L5/L6 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("L6")){
			in_signing_reason = mdr_obj.get("373").toString();	// AMEX L5/L6 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("E3")){
			in_signing_reason = mdr_obj.get("395").toString();	// AMEX E3 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("E6")){
			in_signing_reason = mdr_obj.get("396").toString();	// AMEX E6 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("E9")){
			in_signing_reason = mdr_obj.get("397").toString();	// AMEX E9 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("E12")){
			in_signing_reason = mdr_obj.get("398").toString();	// AMEX E12 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("E18")){
			in_signing_reason = mdr_obj.get("399").toString();	// AMEX E18 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("E24")){
			in_signing_reason = mdr_obj.get("400").toString();	// AMEX E24 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("E30")){
			in_signing_reason = mdr_obj.get("401").toString();	// AMEX E30 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		} else if(p_type.equals("E36")){
			in_signing_reason = mdr_obj.get("402").toString();	// AMEX E36 - Signing Reason
			in_old_merchant_no = mdr_obj.get("325").toString();	// AMEX POS - Old Merchant No
		}
		
		s_arr[0] = c.getMerchant().getRegisteredNo();
		
		if(otherinfo_obj != null){
			s_arr[1] = otherinfo_obj.get("servicing_rep").toString();
		}
		
		s_arr[2] = in_signing_reason;
		
		if(otherinfo_obj != null){
			s_arr[3] = otherinfo_obj.get("sales_rep").toString();
		}
		
		s_arr[4] = in_old_merchant_no;
		
		return s_arr;
	}
	
	public static void AMAA01(String addr_type, Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(10);
		
		JSONObject mdr_obj = null;
		JSONObject addr_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		
		if(addr_type.equals("SA") && c_outlet.getOutlet().getAddress2().length() > 0){
			addr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress2());
			
		} else if(addr_type.equals("CO") && c_outlet.getOutlet().getAddress3().length() > 0){
			addr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress3());
			
		} else if(addr_type.equals("PA") && c_outlet.getOutlet().getAddress().length() > 0){
			addr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress());
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "AMAA01-" + addr_type;
		System.out.println("*** " + screen_id + " ***");
		
		// Product ID : AMEX_POS
		String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		
		if(in_283 != null && in_283.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("POS", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_POS", s_arr);
		}
		
		// Product ID : AMEX_MO
		String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
		
		if(in_284 != null && in_284.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("MO", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_MO", s_arr);
		}
		
		// Product ID : AMEX_E_Commerce
		String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
		
		if(in_287 != null && in_287.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("EC", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
		}
		
		// Product ID : AMEX_RPS
		String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
		
		if(in_286 != null && in_286.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("RPS", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_RPS", s_arr);
		}
		
		// Product ID : AMEX_M2U
		String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
		
		if(in_288 != null && in_288.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("M2U", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_M2U", s_arr);
		}
		
		// Product ID : AMEX_L5 / AMEX_L6
		String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		
		if(in_349 != null && in_349.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("L5", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L5", s_arr);
			
			s_arr = AutoScript.AMAA01AmexX("L6", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L6", s_arr);
		}
		
		
		// Product ID : AMEX_E3
		String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
		
		if(in_435 != null && in_435.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("E3", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E3", s_arr);
		}
		
		// Product ID : AMEX_E6
		String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
		
		if(in_436 != null && in_436.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("E6", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E6", s_arr);
		}
		
		// Product ID : AMEX_E9
		String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
		
		if(in_437 != null && in_437.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("E9", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E9", s_arr);
		}
		
		// Product ID : AMEX_E12
		String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
		
		if(in_438 != null && in_438.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("E12", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E12", s_arr);
		}
		
		// Product ID : AMEX_E18
		String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
		
		if(in_439 != null && in_439.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("E18", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E18", s_arr);
		}
		
		// Product ID : AMEX_E24
		String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
		
		if(in_440 != null && in_440.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("E24", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E24", s_arr);
		}
		
		// Product ID : AMEX_E30
		String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
		
		if(in_441 != null && in_441.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("E30", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E30", s_arr);
		}
		
		// Product ID : AMEX_E36
		String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
		
		if(in_442 != null && in_442.length() > 0){
			s_arr = AutoScript.AMAA01AmexX("E36", c, c_outlet, mdr_obj, addr_obj);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E36", s_arr);
		} 
	}
	
	
	public static String[] AMAA01AmexX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject addr_obj){
		String[] s_arr = AutoScript.init_arr(10);
		
		s_arr[0] = AutoScript.today_date(AutoScript.date_format);
		
		if(addr_obj != null){
			String addr = addr_obj.get("line_1").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[1] = addr;
			
			addr = addr_obj.get("line_2").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[2] = addr;
			
			addr = addr_obj.get("line_3").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[3] = addr;
			
			addr = addr_obj.get("line_4").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[4] = addr;
			
			addr = addr_obj.get("city").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[5] = addr;
			
			s_arr[6] = addr_obj.get("region_code").toString();
			s_arr[7] = addr_obj.get("postal_code").toString();
		}
		
		s_arr[8] = c.getCountryCode();
		s_arr[9] = c_outlet.getOutlet().getCTFax();
		
		return s_arr;
	}
	
	
	public static void AMAB01(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(8);
		
		JSONObject mdr_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "AMAB01";
		System.out.println("*** " + screen_id + " ***");
		
		int amex_auth_index = 0;
		
		// Product ID : AMEX_POS
		String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		
		if(in_283 != null && in_283.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("POS", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_POS", s_arr);
		}
		
		// Product ID : AMEX_MO
		String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
		
		if(in_284 != null && in_284.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("MO", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_MO", s_arr);
		}
		
		// Product ID : AMEX_E_Commerce
		String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
		
		if(in_287 != null && in_287.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("EC", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
		}
		
		// Product ID : AMEX_RPS
		String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
		
		if(in_286 != null && in_286.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("RPS", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_RPS", s_arr);
		}
		
		// Product ID : AMEX_M2U
		String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
		
		if(in_288 != null && in_288.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("M2U", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_M2U", s_arr);
		}
		
		// Product ID : AMEX_L5 / AMEX_L6
		String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		
		if(in_349 != null && in_349.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("L5", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L5", s_arr);
			
			s_arr = AutoScript.AMAB0XAmexX("L6", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L6", s_arr);
		}
		
		
		// Product ID : AMEX_E3
		String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
		
		if(in_435 != null && in_435.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E3", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E3", s_arr);
		}
		
		// Product ID : AMEX_E6
		String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
		
		if(in_436 != null && in_436.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E6", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E6", s_arr);
		}
		
		// Product ID : AMEX_E9
		String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
		
		if(in_437 != null && in_437.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E9", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E9", s_arr);
		}
		
		// Product ID : AMEX_E12
		String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
		
		if(in_438 != null && in_438.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E12", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E12", s_arr);
		}
		
		// Product ID : AMEX_E18
		String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
		
		if(in_439 != null && in_439.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E18", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E18", s_arr);
		}
		
		// Product ID : AMEX_E24
		String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
		
		if(in_440 != null && in_440.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E24", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E24", s_arr);
		}
		
		// Product ID : AMEX_E30
		String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
		
		if(in_441 != null && in_441.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E30", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E30", s_arr);
		}
		
		// Product ID : AMEX_E36
		String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
		
		if(in_442 != null && in_442.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E36", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E36", s_arr);
		} 
	}
	
	public static void AMAB02(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(8);
		
		JSONObject mdr_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "AMAB02";
		System.out.println("*** " + screen_id + " ***");
		
		int amex_auth_index = 1;
		
		// Product ID : AMEX_POS
		String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		
		if(in_283 != null && in_283.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("POS", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_POS", s_arr);
		}
		
		// Product ID : AMEX_MO
		String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
		
		if(in_284 != null && in_284.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("MO", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_MO", s_arr);
		}
		
		// Product ID : AMEX_E_Commerce
		String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
		
		if(in_287 != null && in_287.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("EC", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
		}
		
		// Product ID : AMEX_RPS
		String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
		
		if(in_286 != null && in_286.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("RPS", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_RPS", s_arr);
		}
		
		// Product ID : AMEX_M2U
		String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
		
		if(in_288 != null && in_288.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("M2U", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_M2U", s_arr);
		}
		
		// Product ID : AMEX_L5 / AMEX_L6
		String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		
		if(in_349 != null && in_349.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("L5", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L5", s_arr);
			
			s_arr = AutoScript.AMAB0XAmexX("L6", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L6", s_arr);
		}
		
		
		// Product ID : AMEX_E3
		String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
		
		if(in_435 != null && in_435.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E3", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E3", s_arr);
		}
		
		// Product ID : AMEX_E6
		String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
		
		if(in_436 != null && in_436.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E6", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E6", s_arr);
		}
		
		// Product ID : AMEX_E9
		String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
		
		if(in_437 != null && in_437.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E9", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E9", s_arr);
		}
		
		// Product ID : AMEX_E12
		String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
		
		if(in_438 != null && in_438.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E12", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E12", s_arr);
		}
		
		// Product ID : AMEX_E18
		String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
		
		if(in_439 != null && in_439.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E18", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E18", s_arr);
		}
		
		// Product ID : AMEX_E24
		String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
		
		if(in_440 != null && in_440.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E24", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E24", s_arr);
		}
		
		// Product ID : AMEX_E30
		String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
		
		if(in_441 != null && in_441.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E30", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E30", s_arr);
		}
		
		// Product ID : AMEX_E36
		String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
		
		if(in_442 != null && in_442.length() > 0){
			s_arr = AutoScript.AMAB0XAmexX("E36", c, c_outlet, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E36", s_arr);
		} 
	}
	
	public static String[] AMAB0XAmexX(String p_type, Casemast c, CaseOutlet c_outlet, int amex_index){
		String[] s_arr = AutoScript.init_arr(8);
		
		String amex_auth_sign = "";
		ArrayList<TreeMap<String, String>> amex_entries = new ArrayList<TreeMap<String, String>>();
		
		amex_auth_sign = c.getMerchant().getAmexAuthSign();
		
		JSONArray amex_auth_sign_arr = (JSONArray) JSONValue.parse(amex_auth_sign);
		for(int k = 0; k < amex_auth_sign_arr.size(); k++) {
			String string = amex_auth_sign_arr.get(k).toString();
			JSONObject obj = (JSONObject)JSONValue.parse(string);
			TreeMap<String, String> temp = new TreeMap<String, String>();
			temp.put("title", obj.get("title").toString().trim());
			temp.put("name", obj.get("name").toString().trim());
			temp.put("designation", obj.get("designation").toString().trim());
			temp.put("ic", obj.get("ic_no").toString().trim());
			temp.put("dob", obj.get("date_of_birth").toString().trim());
			temp.put("gender", obj.get("gender").toString().trim());
			
			amex_entries.add(temp);
		}
		
		
		s_arr[0] = amex_entries.isEmpty() == false ? amex_entries.get(amex_index).get("ic") : "";
		s_arr[1] = amex_entries.isEmpty() == false ? amex_entries.get(amex_index).get("name") : "";
		s_arr[2] = amex_entries.isEmpty() == false ? amex_entries.get(amex_index).get("designation") : "";
		s_arr[3] = amex_entries.isEmpty() == false ? amex_entries.get(amex_index).get("title") : "";
		s_arr[4] = c_outlet.getOutlet().getCTTel();
		s_arr[5] = "2";
		s_arr[6] = amex_entries.isEmpty() == false ? amex_entries.get(amex_index).get("dob") : "";
		
		if(amex_entries.isEmpty()){
			s_arr[7] = "3";
		} else {
			if(amex_entries.get(amex_index).get("gender").equals("Male")){
				s_arr[7] = "1";
			} else if(amex_entries.get(amex_index).get("gender").equals("Female")){
				s_arr[7] = "2";
			} else {
				s_arr[7] = "3";
			}
		}
		
		return s_arr;
	}
	
	
	public static void AMDM01(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(12);
		
		JSONObject mdr_obj = null;
		JSONObject pymt_obj = null;
		JSONObject addr_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		if(c_outlet.getOutlet().getPaymentOpt().length() > 0){
			pymt_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getPaymentOpt());
		}
		
		if(c_outlet.getOutlet().getAddress().length() > 0){
			addr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress2());
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "AMDM01";
		System.out.println("*** " + screen_id + " ***");
		
		
		int amex_auth_index = 0;
		
		
		// Product ID : AMEX_POS
		String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		
		if(in_283 != null && in_283.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("POS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_POS", s_arr);
		}
		
		// Product ID : AMEX_MO
		String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
		
		if(in_284 != null && in_284.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("MO", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_MO", s_arr);
		}
		
		// Product ID : AMEX_E_Commerce
		String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
		
		if(in_287 != null && in_287.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("EC", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
		}
		
		// Product ID : AMEX_RPS
		String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
		
		if(in_286 != null && in_286.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("RPS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_RPS", s_arr);
		}
		
		// Product ID : AMEX_M2U
		String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
		
		if(in_288 != null && in_288.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("M2U", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_M2U", s_arr);
		}
		
		// Product ID : AMEX_L5 / AMEX_L6
		String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		
		if(in_349 != null && in_349.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("L5", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L5", s_arr);
			
			s_arr = AutoScript.AMDM0XAmexX("L6", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L6", s_arr);
		}
		
		
		// Product ID : AMEX_E3
		String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
		
		if(in_435 != null && in_435.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E3", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E3", s_arr);
		}
		
		// Product ID : AMEX_E6
		String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
		
		if(in_436 != null && in_436.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E6", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E6", s_arr);
		}
		
		// Product ID : AMEX_E9
		String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
		
		if(in_437 != null && in_437.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E9", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E9", s_arr);
		}
		
		// Product ID : AMEX_E12
		String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
		
		if(in_438 != null && in_438.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E12", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E12", s_arr);
		}
		
		// Product ID : AMEX_E18
		String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
		
		if(in_439 != null && in_439.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E18", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E18", s_arr);
		}
		
		// Product ID : AMEX_E24
		String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
		
		if(in_440 != null && in_440.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E24", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E24", s_arr);
		}
		
		// Product ID : AMEX_E30
		String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
		
		if(in_441 != null && in_441.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E30", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E30", s_arr);
		}
		
		// Product ID : AMEX_E36
		String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
		
		if(in_442 != null && in_442.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E36", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E36", s_arr);
		} 
	}
	
	public static void AMDM02(Casemast c, CaseOutlet c_outlet) throws Exception{
		String[] s_arr = AutoScript.init_arr(12);
		
		JSONObject mdr_obj = null;
		JSONObject pymt_obj = null;
		JSONObject addr_obj = null;
		
		if(c_outlet.getOutlet().getMDRRate().length() > 0){
			mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		}
		
		if(mdr_obj == null){
			return;
		}
		
		if(c_outlet.getOutlet().getPaymentOpt().length() > 0){
			pymt_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getPaymentOpt());
		}
		
		if(c_outlet.getOutlet().getAddress().length() > 0){
			addr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress2());
		}
		
		
		String[] data_arr = AutoScript.DATA(c, c_outlet);
		
		String screen_id = "AMDM02";
		System.out.println("*** " + screen_id + " ***");
		
		
		int amex_auth_index = 1;
		
		
		// Product ID : AMEX_POS
		String in_283 = mdr_obj.get("283").toString();	// AMEX POS - Amex Mid No
		
		if(in_283 != null && in_283.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("POS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_POS", s_arr);
		}
		
		// Product ID : AMEX_MO
		String in_284 = mdr_obj.get("284").toString();	// AMEX MO - Amex Mid No
		
		if(in_284 != null && in_284.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("MO", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_MO", s_arr);
		}
		
		// Product ID : AMEX_E_Commerce
		String in_287 = mdr_obj.get("287").toString();	// AMEX EC - Amex Mid No
		
		if(in_287 != null && in_287.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("EC", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E_Commerce", s_arr);
		}
		
		// Product ID : AMEX_RPS
		String in_286 = mdr_obj.get("286").toString();	// AMEX RPS - Amex Mid No
		
		if(in_286 != null && in_286.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("RPS", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_RPS", s_arr);
		}
		
		// Product ID : AMEX_M2U
		String in_288 = mdr_obj.get("288").toString();	// AMEX M2U - Amex Mid No
		
		if(in_288 != null && in_288.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("M2U", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_M2U", s_arr);
		}
		
		// Product ID : AMEX_L5 / AMEX_L6
		String in_349 = mdr_obj.get("349").toString();	// AMEX L5/L6 - MCC Code
		
		if(in_349 != null && in_349.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("L5", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L5", s_arr);
			
			s_arr = AutoScript.AMDM0XAmexX("L6", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_L6", s_arr);
		}
		
		
		// Product ID : AMEX_E3
		String in_435 = mdr_obj.get("435").toString();	// AMEX E3 - MCC Code
		
		if(in_435 != null && in_435.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E3", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E3", s_arr);
		}
		
		// Product ID : AMEX_E6
		String in_436 = mdr_obj.get("436").toString();	// AMEX E6 - MCC Code
		
		if(in_436 != null && in_436.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E6", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E6", s_arr);
		}
		
		// Product ID : AMEX_E9
		String in_437 = mdr_obj.get("437").toString();	// AMEX E9 - MCC Code
		
		if(in_437 != null && in_437.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E9", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E9", s_arr);
		}
		
		// Product ID : AMEX_E12
		String in_438 = mdr_obj.get("438").toString();	// AMEX E12 - MCC Code
		
		if(in_438 != null && in_438.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E12", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E12", s_arr);
		}
		
		// Product ID : AMEX_E18
		String in_439 = mdr_obj.get("439").toString();	// AMEX E18 - MCC Code
		
		if(in_439 != null && in_439.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E18", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E18", s_arr);
		}
		
		// Product ID : AMEX_E24
		String in_440 = mdr_obj.get("440").toString();	// AMEX E24 - MCC Code
		
		if(in_440 != null && in_440.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E24", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E24", s_arr);
		}
		
		// Product ID : AMEX_E30
		String in_441 = mdr_obj.get("441").toString();	// AMEX E30 - MCC Code
		
		if(in_441 != null && in_441.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E30", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E30", s_arr);
		}
		
		// Product ID : AMEX_E36
		String in_442 = mdr_obj.get("442").toString();	// AMEX E36 - MCC Code
		
		if(in_442 != null && in_442.length() > 0){
			s_arr = AutoScript.AMDM0XAmexX("E36", c, c_outlet, mdr_obj, pymt_obj, addr_obj, amex_auth_index);
			s_arr = AutoScript.concat(s_arr, data_arr);
			
			AutoScript.save(screen_id, "AMEX_E36", s_arr);
		} 
	}
	
	public static String[] AMDM0XAmexX(String p_type, Casemast c, CaseOutlet c_outlet, JSONObject mdr_obj, JSONObject pymt_obj, JSONObject addr_obj, int amex_index){
		String[] s_arr = AutoScript.init_arr(12);
		
		String amex_1 = "";
		String amex_2 = "";
		String amex_3 = "";
		String amex_8 = "";
		
		if(pymt_obj != null){
			amex_1 = pymt_obj.get("amex_1").toString();
			amex_2 = pymt_obj.get("amex_2").toString();
			amex_3 = pymt_obj.get("amex_3").toString();
			amex_8 = pymt_obj.get("amex_8").toString();
		}
		
		
		String in_rate = "";
		String in_agreement_code = "";
		
		if(p_type.equals("POS")){
			in_rate = mdr_obj.get("301").toString();		// AMEX POS - Base Disc Rate (A)
			in_agreement_code = mdr_obj.get("289").toString();	// AMEX POS - Agreement Code
		} else if(p_type.equals("MO")){
			in_rate = mdr_obj.get("302").toString();		// AMEX MO - Base Disc Rate (A)
			in_agreement_code = mdr_obj.get("290").toString();	// AMEX MO - Agreement Code
		} else if(p_type.equals("EC")){
			in_rate = mdr_obj.get("305").toString();		// AMEX E-Commerce - Base Disc Rate (A)
			in_agreement_code = mdr_obj.get("293").toString();	// AMEX E-Commerce - Agreement Code
		} else if(p_type.equals("RPS")){
			in_rate = mdr_obj.get("304").toString();		// AMEX RPS - Base Disc Rate (A)
			in_agreement_code = mdr_obj.get("292").toString();	// AMEX RPS - Agreement Code
		} else if(p_type.equals("M2U")){
			in_rate = mdr_obj.get("306").toString();		// AMEX M2U - Base Disc Rate (A)
			in_agreement_code = mdr_obj.get("294").toString();	// AMEX M2U - Agreement Code
		} else if(p_type.equals("L5")){
			in_rate = "";
			in_agreement_code = mdr_obj.get("361").toString();	// AMEX L5/L6 - Agreement Code
		} else if(p_type.equals("L6")){
			in_rate = "";
			in_agreement_code = mdr_obj.get("361").toString();	// AMEX L5/L6 - Agreement Code
		} else if(p_type.equals("E3")){
			in_rate = mdr_obj.get("467").toString();		// AMEX E3 - Amex (%)
			in_agreement_code = mdr_obj.get("379").toString();	// AMEX E3 - Agreement Code
		} else if(p_type.equals("E6")){
			in_rate = mdr_obj.get("468").toString();		// AMEX E6 - Amex (%)
			in_agreement_code = mdr_obj.get("380").toString();	// AMEX E6 - Agreement Code
		} else if(p_type.equals("E9")){
			in_rate = mdr_obj.get("469").toString();		// AMEX E9 - Amex (%)
			in_agreement_code = mdr_obj.get("381").toString();	// AMEX E9 - Agreement Code
		} else if(p_type.equals("E12")){
			in_rate = mdr_obj.get("470").toString();		// AMEX E12 - Amex (%)
			in_agreement_code = mdr_obj.get("382").toString();	// AMEX E12 - Agreement Code
		} else if(p_type.equals("E18")){
			in_rate = mdr_obj.get("471").toString();		// AMEX E18 - Amex (%)
			in_agreement_code = mdr_obj.get("383").toString();	// AMEX E18 - Agreement Code
		} else if(p_type.equals("E24")){
			in_rate = mdr_obj.get("472").toString();		// AMEX E24 - Amex (%)
			in_agreement_code = mdr_obj.get("384").toString();	// AMEX E24 - Agreement Code
		} else if(p_type.equals("E30")){
			in_rate = mdr_obj.get("473").toString();		// AMEX E30 - Amex (%)
			in_agreement_code = mdr_obj.get("385").toString();	// AMEX E30 - Agreement Code
		} else if(p_type.equals("E36")){
			in_rate = mdr_obj.get("474").toString();		// AMEX E36 - Amex (%)
			in_agreement_code = mdr_obj.get("386").toString();	// AMEX E36 - Agreement Code
		}
		
		
		
		String amex_auth_sign = "";
		ArrayList<TreeMap<String, String>> amex_entries = new ArrayList<TreeMap<String, String>>();
		
		amex_auth_sign = c.getMerchant().getAmexAuthSign();
		
		JSONArray amex_auth_sign_arr = (JSONArray) JSONValue.parse(amex_auth_sign);
		for(int k = 0; k < amex_auth_sign_arr.size(); k++) {
			String string = amex_auth_sign_arr.get(k).toString();
			JSONObject obj = (JSONObject)JSONValue.parse(string);
			TreeMap<String, String> temp = new TreeMap<String, String>();
			temp.put("title", obj.get("title").toString().trim());
			temp.put("name", obj.get("name").toString().trim());
			temp.put("designation", obj.get("designation").toString().trim());
			temp.put("ic", obj.get("ic_no").toString().trim());
			temp.put("dob", obj.get("date_of_birth").toString().trim());
			temp.put("gender", obj.get("gender").toString().trim());
			
			amex_entries.add(temp);
		}
		
		
		if(in_rate.length() > 0){
			s_arr[0] = AutoScript.format_decimal(in_rate, 5);
		}
		
		Date d1 = new Date();
		Date d2 = new Date(d1.getTime() + (1 * 24 * 60 * 60 * AutoScript.ms));
		
		s_arr[1] = AutoScript.today_date(AutoScript.date_format, d2);
		
		if(p_type.equals("L5") || p_type.equals("L6")){
			s_arr[2] = "";
		} else {
			s_arr[2] = amex_8;
		}
		
		String reg_name = c_outlet.getOutlet().getMerchant().getRegisteredName();
		if(reg_name.length() < 38){
			reg_name = String.format("%1$-38s", reg_name);
		}
		
		s_arr[3] = reg_name;
		
		if(addr_obj != null){
			String addr = addr_obj.get("line_1").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[4] = addr;
			
			addr = addr_obj.get("line_2").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[5] = addr;
			
			addr = addr_obj.get("line_3").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[6] = addr;
			
			addr = addr_obj.get("line_4").toString();
			addr = addr.replace(",", "&coma;");
			s_arr[7] = addr;
		}
		
		
		if(amex_1.equals("credit_maybank")){
			s_arr[8] = amex_2;
		} else if(amex_1.equals("interbank_giro")){
			s_arr[8] = amex_3;
		}
		
		
		s_arr[9] = amex_entries.isEmpty() == false ? amex_entries.get(amex_index).get("ic") : "";
		
		if(amex_index == 0){
			s_arr[10] = "009";
		} else {
			s_arr[10] = "010";
		}
		
		s_arr[11] = in_agreement_code;
		
		return s_arr;
	}
}
